diff options
Diffstat (limited to 'script/files.lua')
-rw-r--r-- | script/files.lua | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/script/files.lua b/script/files.lua index fd9a55ab..48a5b58b 100644 --- a/script/files.lua +++ b/script/files.lua @@ -116,14 +116,15 @@ function m.setText(uri, text) m._pairsCache = nil end local suc, newText = plugin.dispatch('OnSetText', originUri, text) - if suc then - text = newText + if not suc then + newText = text end local file = m.fileMap[uri] - if file.text == text then + if file.text == newText then return end - file.text = text + file.text = newText + file.originText = text m.linesMap[uri] = nil m.astMap[uri] = nil file.cache = {} @@ -159,6 +160,18 @@ function m.getText(uri) return file.text end +--- 获取文件原始文本 +---@param uri uri +---@return string text +function m.getOriginText(uri) + uri = getUriKey(uri) + local file = m.fileMap[uri] + if not file then + return nil + end + return file.originText +end + --- 移除文件 ---@param uri uri function m.remove(uri) |