From 2704a977b8b0b48bd09659c73ee26243e8798eb2 Mon Sep 17 00:00:00 2001 From: Shuanglei Tao Date: Fri, 28 Jun 2024 18:51:09 +0800 Subject: [PATCH] fix menu title abbreviation --- src/lua/dyn_menu.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/lua/dyn_menu.lua b/src/lua/dyn_menu.lua index 0452815..cab9944 100644 --- a/src/lua/dyn_menu.lua +++ b/src/lua/dyn_menu.lua @@ -171,10 +171,16 @@ local function utf8_sub(s, i, j) return table.concat(t) end +-- return the length of a utf8 string +local function utf8_len(s) + local _, count = s:gsub(UTF8_PATTERN, "") + return count +end + -- abbreviate title if it's too long local function abbr_title(str) if not str or str == '' then return '' end - if o.max_title_length > 0 and str:len() > o.max_title_length then + if o.max_title_length > 0 and utf8_len(str) > o.max_title_length then return utf8_sub(str, 1, o.max_title_length) .. '...' end return str