From de7c1e20c5148860c26cec8aaab11cd34aac9857 Mon Sep 17 00:00:00 2001 From: Aleksa Sarai Date: Mon, 25 Oct 2021 17:45:26 +1100 Subject: [PATCH] languagesupport: check that ui.languagesupport is non-nil Now that FileManager registers its UI modules in the same way as Reader, this shouldn't be necessary but this protects us against some other app creating a ReaderDictionary instance without having ui.languagesupport registered properly. Signed-off-by: Aleksa Sarai --- frontend/apps/reader/modules/readerdictionary.lua | 2 +- frontend/apps/reader/modules/readerhighlight.lua | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/frontend/apps/reader/modules/readerdictionary.lua b/frontend/apps/reader/modules/readerdictionary.lua index 258938fad..67fe674f3 100644 --- a/frontend/apps/reader/modules/readerdictionary.lua +++ b/frontend/apps/reader/modules/readerdictionary.lua @@ -801,7 +801,7 @@ end function ReaderDictionary:startSdcv(word, dict_names, fuzzy_search) local words = {word} - if self.ui.languagesupport:hasActiveLanguagePlugins() then + if self.ui.languagesupport and self.ui.languagesupport:hasActiveLanguagePlugins() then -- Get any other candidates from any language-specific plugins we have. -- We prefer the originally selected word first (in case there is a -- dictionary entry for whatever text the user selected). diff --git a/frontend/apps/reader/modules/readerhighlight.lua b/frontend/apps/reader/modules/readerhighlight.lua index 7deaa0552..4c1851016 100644 --- a/frontend/apps/reader/modules/readerhighlight.lua +++ b/frontend/apps/reader/modules/readerhighlight.lua @@ -864,7 +864,7 @@ function ReaderHighlight:onHold(arg, ges) self.selected_link = link end - if self.ui.languagesupport:hasActiveLanguagePlugins() then + if self.ui.languagesupport and self.ui.languagesupport:hasActiveLanguagePlugins() then -- If this is a language where pan-less word selection needs some -- extra work above and beyond what the document engine gives us -- from getWordFromPosition, call the relevant language-specific @@ -1338,7 +1338,7 @@ function ReaderHighlight:highlightFromHoldPos() if self.hold_pos then if not self.selected_text then self.selected_text = self.ui.document:getTextFromPositions(self.hold_pos, self.hold_pos) - if self.ui.languagesupport:hasActiveLanguagePlugins() then + if self.ui.languagesupport and self.ui.languagesupport:hasActiveLanguagePlugins() then -- Match language-specific expansion you'd get from self:onHold(). local new_selected_text = self.ui.languagesupport:improveWordSelection(self.selected_text) if new_selected_text then