mirror of
https://github.com/koreader/koreader.git
synced 2025-12-13 20:36:53 +01:00
dictquicklookup(fix): use self.region for matching hold event
This commit is contained in:
@@ -81,12 +81,14 @@ function DictQuickLookup:init()
|
||||
HoldWord = {
|
||||
GestureRange:new{
|
||||
ges = "hold",
|
||||
range = function() return self.dimen end,
|
||||
range = function()
|
||||
return self.region
|
||||
end,
|
||||
},
|
||||
-- callback function when HoldWord is handled as args
|
||||
args = function(word)
|
||||
self.ui:handleEvent(Event:new("LookupWord",
|
||||
word, self.word_box))
|
||||
self.ui:handleEvent(
|
||||
Event:new("LookupWord", word, self.word_box))
|
||||
end
|
||||
},
|
||||
}
|
||||
@@ -293,6 +295,7 @@ function DictQuickLookup:onShow()
|
||||
end
|
||||
|
||||
function DictQuickLookup:getHighlightedItem()
|
||||
if not self.ui then return end
|
||||
return self.ui.highlight:getHighlightBookmarkItem()
|
||||
end
|
||||
|
||||
|
||||
25
spec/unit/textboxwidget_spec.lua
Normal file
25
spec/unit/textboxwidget_spec.lua
Normal file
@@ -0,0 +1,25 @@
|
||||
describe("TextBoxWidget module", function()
|
||||
local TextBoxWidget, Font
|
||||
setup(function()
|
||||
require("commonrequire")
|
||||
Font = require("ui/font")
|
||||
TextBoxWidget = require("ui/widget/textboxwidget")
|
||||
end)
|
||||
|
||||
it("should select the correct word on HoldWord event", function()
|
||||
local tw = TextBoxWidget:new{
|
||||
dimen = {x = 0, y = 0},
|
||||
face = Font:getFace("cfont", 25),
|
||||
text = 'YOOOOOOOOOOOOOOOO\nFoo.\nBar.',
|
||||
}
|
||||
tw:onHoldWord(function(w)
|
||||
assert.is.same(w, 'YOOOOOOOOOOOOOOOO')
|
||||
end, {pos={x=110,y=4}})
|
||||
tw:onHoldWord(function(w)
|
||||
assert.is.same(w, 'Foo')
|
||||
end, {pos={x=0,y=50}})
|
||||
tw:onHoldWord(function(w)
|
||||
assert.is.same(w, 'Bar')
|
||||
end, {pos={x=20,y=80}})
|
||||
end)
|
||||
end)
|
||||
Reference in New Issue
Block a user