diff --git a/frontend/apps/reader/modules/readertypeset.lua b/frontend/apps/reader/modules/readertypeset.lua index ea03fc6f1..dfaa76080 100644 --- a/frontend/apps/reader/modules/readertypeset.lua +++ b/frontend/apps/reader/modules/readertypeset.lua @@ -75,10 +75,15 @@ function ReaderTypeset:onReadSettings(config) self:onSetPageMargins(self.unscaled_margins) self.sync_t_b_page_margins = self.configurable.sync_t_b_page_margins == 1 and true or false - -- default to disable TXT formatting as it does more harm than good - self.txt_preformatted = config:readSetting("txt_preformatted") - or G_reader_settings:readSetting("txt_preformatted") - or 1 + if self.ui.document.is_txt then + -- default to disable TXT formatting as it does more harm than good + self.txt_preformatted = config:readSetting("txt_preformatted") + or G_reader_settings:readSetting("txt_preformatted") + or 1 + else + -- for other formats, it affects crengine cache + self.txt_preformatted = 1 + end self.ui.document:setTxtPreFormatted(self.txt_preformatted) -- default to disable smooth scaling @@ -313,27 +318,30 @@ This stylesheet is to be used only with FB2 and FB3 documents, which are not cla sub_item_table = obsoleted_table, separator = true, }) - table.insert(style_table, { - text_func = function() - return _("Preformatted text in TXT files") .. (G_reader_settings:has("txt_preformatted") and "" or " ★") - end, - checked_func = function() - return self.txt_preformatted == 1 - end, - callback = function() - self.txt_preformatted = self.txt_preformatted == 1 and 0 or 1 - self.ui.doc_settings:saveSetting("txt_preformatted", self.txt_preformatted) - self.ui.rolling:showReloadConfirmBox() - end, - hold_callback = function(touchmenu_instance) - if G_reader_settings:has("txt_preformatted") then - G_reader_settings:delSetting("txt_preformatted") - else - G_reader_settings:saveSetting("txt_preformatted", 0) - end - touchmenu_instance:updateItems() - end, - }) + if self.ui.document.is_txt then + table.insert(style_table, { + text_func = function() + return _("Auto-detect TXT files layout") .. (G_reader_settings:has("txt_preformatted") and " ★" or "") + end, + checked_func = function() + return self.txt_preformatted == 0 + end, + callback = function() + self.txt_preformatted = self.txt_preformatted == 1 and 0 or 1 + self.ui.doc_settings:saveSetting("txt_preformatted", self.txt_preformatted) + -- setting txt_preformatted for the open document causes segfault, hence reload + self.ui.rolling:showReloadConfirmBox() + end, + hold_callback = function(touchmenu_instance) + if G_reader_settings:has("txt_preformatted") then + G_reader_settings:delSetting("txt_preformatted") + else + G_reader_settings:saveSetting("txt_preformatted", 0) + end + touchmenu_instance:updateItems() + end, + }) + end return style_table end