2
0
mirror of https://github.com/koreader/koreader synced 2024-11-18 03:25:46 +00:00

Show full ToC entry on hold (#6729)

Fix #6728
This commit is contained in:
NiLuJe 2020-09-30 19:56:56 +02:00 committed by GitHub
parent f0f0cfd167
commit ec3ec8dc21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 48 additions and 8 deletions

View File

@ -91,7 +91,7 @@ function TweakInfoWidget:init()
f:close()
end
end
self.css_text = css:gsub("^%s+", ""):gsub("%s+$", "")
self.css_text = util.trim(css)
self.css_frame = FrameContainer:new{
bordersize = Size.border.thin,
padding = Size.padding.large,
@ -309,7 +309,7 @@ function ReaderStyleTweak:updateCssText(apply)
-- re-reading it, but this will allow a user to experiment
-- wihout having to restart KOReader
end
css = css:gsub("^%s+", ""):gsub("%s+$", "")
css = util.trim(css)
table.insert(css_snippets, css)
end
if self.book_style_tweak and self.book_style_tweak_enabled then

View File

@ -7,10 +7,12 @@ local Event = require("ui/event")
local Font = require("ui/font")
local GestureRange = require("ui/gesturerange")
local Geom = require("ui/geometry")
local InfoMessage = require("ui/widget/infomessage")
local InputContainer = require("ui/widget/container/inputcontainer")
local Menu = require("ui/widget/menu")
local UIManager = require("ui/uimanager")
local logger = require("logger")
local util = require("util")
local _ = require("gettext")
local Screen = Device.screen
local T = require("ffi/util").template
@ -582,6 +584,17 @@ function ReaderToc:onShowToc()
end
end
function toc_menu:onMenuHold(item)
-- Trim toc_indent
local trimmed_text = util.ltrim(item.text)
local infomessage = InfoMessage:new{
show_icon = false,
text = trimmed_text,
}
UIManager:show(infomessage)
return true
end
toc_menu.close_callback = function()
UIManager:close(menu_container)
end

View File

@ -422,7 +422,7 @@ function Device:retrieveNetworkInfo()
std_out = io.popen('2>/dev/null iwconfig | grep ESSID | cut -d\\" -f2')
if std_out then
local ssid = std_out:read("*all")
result = result .. "SSID: " .. ssid:gsub("(.-)%s*$", "%1") .. "\n"
result = result .. "SSID: " .. util.trim(ssid) .. "\n"
std_out:close()
end
if os.execute("ip r | grep -q default") == 0 then

View File

@ -14,7 +14,7 @@ local bor = bit.bor
local util = {}
--- Strips all punctuation marks and spaces from a string.
---- Strips all punctuation marks and spaces from a string.
---- @string text the string to be stripped
---- @treturn string stripped text
function util.stripPunctuation(text)
@ -24,6 +24,33 @@ function util.stripPunctuation(text)
return text:gsub("\226[\128-\131][\128-\191]", ''):gsub("^%p+", ''):gsub("%p+$", '')
end
-- Various whitespace trimming helpers, from http://lua-users.org/wiki/CommonFunctions & http://lua-users.org/wiki/StringTrim
---- Remove leading whitespace from string.
---- @string s the string to be trimmed
---- @treturn string trimmed text
function util.ltrim(s)
return (s:gsub("^%s*", ""))
end
---- Remove trailing whitespace from string.
---- @string s the string to be trimmed
---- @treturn string trimmed text
function util.rtrim(s)
local n = #s
while n > 0 and s:find("^%s", n) do
n = n - 1
end
return s:sub(1, n)
end
---- Remove leading & trailing whitespace from string.
---- @string s the string to be trimmed
---- @treturn string trimmed text
function util.trim(s)
local from = s:match"^%s*()"
return from > #s and "" or s:match(".*%S", from)
end
--[[--
Splits a string by a pattern

View File

@ -1896,7 +1896,7 @@ end
-- For backward compatibility
function ReaderStatistics:importFromFile(base_path, item)
item = string.gsub(item, "^%s*(.-)%s*$", "%1") -- trim
item = util.trim(item)
if item ~= ".stat" then
local statistic_file = FFIUtil.joinPath(base_path, item)
if lfs.attributes(statistic_file, "mode") == "directory" then

View File

@ -31,9 +31,9 @@ describe("util module", function()
for arg1 in util.gsplit(command, "[\"'].-[\"']", true) do
for arg2 in util.gsplit(arg1, "^[^\"'].-%s+", true) do
for arg3 in util.gsplit(arg2, "[\"']", false) do
local trimed = arg3:gsub("^%s*(.-)%s*$", "%1")
if trimed ~= "" then
table.insert(argv, trimed)
local trimmed = util.trim(arg3)
if trimmed ~= "" then
table.insert(argv, trimmed)
end
end
end