Fix some issues with movable dict window (reworked) (#3726)

Clearer rework of this fix (a few commits ago): more explicite,
no need for the additional callback.
pull/3732/head
poire-z 6 years ago committed by GitHub
parent e15a1ab1b3
commit 48da3dc750
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -63,7 +63,6 @@ local DictQuickLookup = InputContainer:new{
-- refresh_callback will be called before we trigger full refresh in onSwipe
refresh_callback = nil,
html_dictionary_link_tapped_callback = nil,
text_selection_in_progress = false,
}
local highlight_strings = {
@ -120,12 +119,12 @@ function DictQuickLookup:init()
ges = "hold",
range = range,
},
-- callback function when HoldStartText is handled as args
args = function(selecting)
-- store the fact we are selecting text in definition,
-- so we don't forward any event to MovableContainer
self.text_selection_in_progress = selecting
end
},
HoldPanText = {
GestureRange:new{
ges = "hold",
range = range,
},
},
HoldReleaseText = {
GestureRange:new{
@ -134,7 +133,6 @@ function DictQuickLookup:init()
},
-- callback function when HoldReleaseText is handled as args
args = function(text, hold_duration)
self.text_selection_in_progress = false
local lookup_target
if hold_duration < 3.0 then
-- do this lookup in the same domain (dict/wikipedia)
@ -154,10 +152,8 @@ function DictQuickLookup:init()
)
end
},
-- These will be forwarded to MovableContainer if we are not currently
-- selecting text in the definition widget
-- These will be forwarded to MovableContainer after some checks
ForwardingTouch = { GestureRange:new{ ges = "touch", range = range, }, },
ForwardingHoldPan = { GestureRange:new{ ges = "hold_pan", range = range, }, },
ForwardingPan = { GestureRange:new{ ges = "pan", range = range, }, },
ForwardingPanRelease = { GestureRange:new{ ges = "pan_release", range = range, }, },
}
@ -533,12 +529,11 @@ function DictQuickLookup:update()
ignore_events = {
-- These have effects over the definition widget, and may
-- or may not be processed by it
"swipe", "hold", "hold_release",
"swipe", "hold", "hold_release", "hold_pan",
-- These do not have direct effect over the definition widget,
-- but may happen while selecting text: we need to check
-- we're not doing text selection and a few other things
-- before forwarding them
"touch", "pan", "pan_release", "hold_pan",
-- a few things before forwarding them
"touch", "pan", "pan_release",
},
self.dict_frame,
}
@ -785,22 +780,27 @@ function DictQuickLookup:onSwipe(arg, ges)
end
function DictQuickLookup:onHoldStartText(_, ges)
-- Event was not processed by definition widget: we are not selecting
self.text_selection_in_progress = false
-- Forward Hold events not processed by TextBoxWidget event handler
-- to our MovableContainer
return self.movable:onMovableHold(_, ges)
end
function DictQuickLookup:onHoldPanText(_, ges)
-- Forward Hold events not processed by TextBoxWidget event handler
-- to our MovableContainer
-- We only forward it if we did forward the Touch
if self.movable._touch_pre_pan_was_inside then
return self.movable:onMovableHoldPan(arg, ges)
end
end
function DictQuickLookup:onHoldReleaseText(_, ges)
-- Event was not processed by definition widget: we are not selecting
self.text_selection_in_progress = false
-- Forward Hold events not processed by TextBoxWidget event handler
-- to our MovableContainer
return self.movable:onMovableHoldRelease(_, ges)
end
-- These 4 event processors are just used to forward these events
-- These 3 event processors are just used to forward these events
-- to our MovableContainer, under certain conditions, to avoid
-- unwanted moves of the window while we are selecting text in
-- the definition widget.
@ -815,29 +815,16 @@ function DictQuickLookup:onForwardingTouch(arg, ges)
end
end
function DictQuickLookup:onForwardingHoldPan(arg, ges)
if not self.text_selection_in_progress then -- don't forward it as we are selecting
-- We only forward it if we did forward the Touch
if self.movable._touch_pre_pan_was_inside then
return self.movable:onMovableHoldPan(arg, ges)
end
end
end
function DictQuickLookup:onForwardingPan(arg, ges)
if not self.text_selection_in_progress then -- don't forward it as we are selecting
-- We only forward it if we did forward the Touch or are currently moving
if self.movable._touch_pre_pan_was_inside or self.movable._moving then
return self.movable:onMovablePan(arg, ges)
end
-- We only forward it if we did forward the Touch or are currently moving
if self.movable._touch_pre_pan_was_inside or self.movable._moving then
return self.movable:onMovablePan(arg, ges)
end
end
function DictQuickLookup:onForwardingPanRelease(arg, ges)
if not self.text_selection_in_progress then -- don't forward it as we are selecting
-- We can forward onMovablePanRelease() does enough checks
return self.movable:onMovablePanRelease(arg, ges)
end
-- We can forward onMovablePanRelease() does enough checks
return self.movable:onMovablePanRelease(arg, ges)
end
function DictQuickLookup:lookupInputWord(hint)

@ -148,20 +148,23 @@ function HtmlBoxWidget:getPosFromAbsPos(abs_pos)
return pos
end
function HtmlBoxWidget:onHoldStartText(callback, ges)
function HtmlBoxWidget:onHoldStartText(_, ges)
self.hold_start_pos = self:getPosFromAbsPos(ges.pos)
if not self.hold_start_pos then
if callback then
callback(false) -- let know we are not selecting
end
return false -- let event be processed by other widgets
end
self.hold_start_tv = TimeVal.now()
if callback then
callback(true) -- let know we are selecting
return true
end
function HtmlBoxWidget:onHoldPan(_, ges)
-- We don't highlight the currently selected text, but just let this
-- event pop up if we are not currently selecting text
if not self.hold_start_pos then
return false
end
return true
end

@ -762,7 +762,7 @@ end
local FIND_START = 1
local FIND_END = 2
function TextBoxWidget:onHoldStartText(callback, ges)
function TextBoxWidget:onHoldStartText(_, ges)
-- store hold start position and timestamp, will be used on release
self.hold_start_x = ges.pos.x - self.dimen.x
self.hold_start_y = ges.pos.y - self.dimen.y
@ -771,16 +771,20 @@ function TextBoxWidget:onHoldStartText(callback, ges)
if self.hold_start_x < 0 or self.hold_start_x > self.dimen.w or
self.hold_start_y < 0 or self.hold_start_y > self.dimen.h then
self.hold_start_tv = nil -- don't process coming HoldRelease event
if callback then
callback(false) -- let know we are not selecting
end
return false -- let event be processed by other widgets
end
self.hold_start_tv = TimeVal.now()
if callback then
callback(true) -- let know we are selecting
return true
end
function TextBoxWidget:onHoldPanText(_, ges)
-- We don't highlight the currently selected text, but just let this
-- event pop up if we are not currently selecting text
if not self.hold_start_tv then
return false
end
-- Don't let that event be processed by other widget
return true
end

Loading…
Cancel
Save