From 558c1bd7733af1b7c76f007d384030772d39c204 Mon Sep 17 00:00:00 2001 From: Takase <20792268+takase1121@users.noreply.github.com> Date: Sun, 24 Oct 2021 14:41:21 +0800 Subject: fix open_ext.lua once and for all --- plugins/open_ext.lua | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'plugins') 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() -- cgit v1.2.3