+7
data/plugins/trimwhitespace.lua
+7
data/plugins/trimwhitespace.lua
···
4
4
5
5
6
6
local function trim_trailing_whitespace(doc)
7
+
local cline, ccol = doc:get_selection()
7
8
for i = 1, #doc.lines do
8
9
local old_text = doc:get_text(i, 1, i, math.huge)
9
10
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
+
10
17
if old_text ~= new_text then
11
18
doc:insert(i, 1, new_text)
12
19
doc:remove(i, #new_text + 1, i, math.huge)