Skip to content

Commit ae48049

Browse files
committed
Changed trimwhitespace to never cause caret to reposition
1 parent 6ec8fc5 commit ae48049

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

data/plugins/trimwhitespace.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,16 @@ local Doc = require "core.doc"
44

55

66
local function trim_trailing_whitespace(doc)
7+
local cline, ccol = doc:get_selection()
78
for i = 1, #doc.lines do
89
local old_text = doc:get_text(i, 1, i, math.huge)
910
local new_text = old_text:gsub("%s*$", "")
11+
12+
-- don't remove whitespace which would cause the caret to reposition
13+
if cline == i and ccol > #new_text then
14+
new_text = old_text:sub(1, ccol - 1)
15+
end
16+
1017
if old_text ~= new_text then
1118
doc:insert(i, 1, new_text)
1219
doc:remove(i, #new_text + 1, i, math.huge)

0 commit comments

Comments
 (0)