Fix a few possible crashes

- TextWidget: avoid crash with small max_width (could happen
  when opening menu on a small emulator window)
- TextWidget: avoid crash if re-used after :free()
- ReaderHighlight:clear(): fix possible crash when
  scheduled and run after document closed
- DictQuickLookup: minor canSearch() tweak ('selected_text'
  is normally available only on multiple words selection,
  but is currently available on single word selection thanks
  to some unrelated side effect)
reviewable/pr7712/r1
poire-z 3 years ago
parent 067ece7281
commit 001d48f6cc

@ -379,6 +379,10 @@ function ReaderHighlight:clear(clear_id)
end
end
self.clear_id = nil -- invalidate id
if not self.ui.document then
-- might happen if scheduled and run after document is closed
return
end
if self.ui.document.info.has_pages then
self.view.highlight.temp = {}
else

@ -75,7 +75,7 @@ function DictQuickLookup:canSearch()
end
else
-- This is to prevent an ineffective button when we're launched from the Reader's menu.
if self.ui.highlight.selected_text then
if self.highlight then
return true
end
end

@ -214,6 +214,9 @@ function TextWidget:_measureWithXText()
-- no bold: xtext does synthetized bold with normal metrics
end
local max_width = self.max_width - reserved_width
if max_width <= 0 then -- avoid _xtext:makeLine() crash
max_width = self.max_width
end
if self.truncate_left then
line_start = self._xtext:getSegmentFromEnd(max_width)
end
@ -311,7 +314,6 @@ end
function TextWidget:setText(text)
if text ~= self.text then
self.text = text
self._updated = false
self:free()
end
end
@ -324,7 +326,6 @@ dbg:guard(TextWidget, "setText",
function TextWidget:setMaxWidth(max_width)
if max_width ~= self.max_width then
self.max_width = max_width
self._updated = false
self:free()
end
end
@ -378,6 +379,7 @@ function TextWidget:free()
self._xtext:free()
self._xtext = nil
end
self._updated = false
end
function TextWidget:onCloseWidget()

Loading…
Cancel
Save