aboutsummaryrefslogtreecommitdiff
path: root/data
diff options
context:
space:
mode:
authorrxi <rxi@users.noreply.github.com>2020-06-19 12:09:00 +0100
committerrxi <rxi@users.noreply.github.com>2020-06-19 12:09:00 +0100
commitae48049695e2a74721323f608e439fb5f5b89da4 (patch)
treeebc4b9603489ea024910af375c668e8aac77b1a6 /data
parent6ec8fc5616ef616dcf84ce028bc220468c4255ca (diff)
downloadlite-xl-ae48049695e2a74721323f608e439fb5f5b89da4.tar.gz
lite-xl-ae48049695e2a74721323f608e439fb5f5b89da4.zip
Changed `trimwhitespace` to never cause caret to reposition
Diffstat (limited to 'data')
-rw-r--r--data/plugins/trimwhitespace.lua7
1 files changed, 7 insertions, 0 deletions
diff --git a/data/plugins/trimwhitespace.lua b/data/plugins/trimwhitespace.lua
index ace1b0f8..d4d25c8f 100644
--- a/data/plugins/trimwhitespace.lua
+++ b/data/plugins/trimwhitespace.lua
@@ -4,9 +4,16 @@ local Doc = require "core.doc"
local function trim_trailing_whitespace(doc)
+ local cline, ccol = doc:get_selection()
for i = 1, #doc.lines do
local old_text = doc:get_text(i, 1, i, math.huge)
local new_text = old_text:gsub("%s*$", "")
+
+ -- don't remove whitespace which would cause the caret to reposition
+ if cline == i and ccol > #new_text then
+ new_text = old_text:sub(1, ccol - 1)
+ end
+
if old_text ~= new_text then
doc:insert(i, 1, new_text)
doc:remove(i, #new_text + 1, i, math.huge)