diff options
author | Takase <20792268+takase1121@users.noreply.github.com> | 2021-10-24 14:41:21 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-24 14:41:21 +0800 |
commit | 558c1bd7733af1b7c76f007d384030772d39c204 (patch) | |
tree | 0bb87c4de8dcd514a27c8352a189889eb61c2f3b /plugins | |
parent | 00894ec021f6689dc8845fed0e86e37c6ad229f2 (diff) | |
download | lite-xl-plugins-558c1bd7733af1b7c76f007d384030772d39c204.tar.gz lite-xl-plugins-558c1bd7733af1b7c76f007d384030772d39c204.zip |
fix open_ext.lua once and for all
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/open_ext.lua | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/plugins/open_ext.lua b/plugins/open_ext.lua index 96532c7..0c7eff1 100644 --- a/plugins/open_ext.lua +++ b/plugins/open_ext.lua @@ -138,18 +138,19 @@ function OpenExtView:draw() end -local function read_doc(doc, limit) - if not doc.abs_filename return "" end - local f = io.open(doc.abs_filename) - local str = f:read(limit) +local function validate_doc(doc) + local f = io.open(doc.abs_filename or "") + if not f then return true end + local str = f:read(128 * 4) -- max bytes for 128 codepoints f:close() - return str + return validate_utf8(str, 128) end + local rootview_open_doc = RootView.open_doc function RootView:open_doc(doc) - local str = read_doc(doc, 128 * 4) -- max bytes for 128 codepoints - if validate_utf8(str, 128) then + -- 128 * 4 == max number of bytes for 128 codepoints + if validate_doc(doc) then return rootview_open_doc(self, doc) else local node = self:get_active_node_default() |