aboutsummaryrefslogtreecommitdiff
path: root/modules/textadept/editing.lua
diff options
context:
space:
mode:
authormitchell <70453897+667e-11@users.noreply.github.com>2013-05-20 12:58:51 -0400
committermitchell <70453897+667e-11@users.noreply.github.com>2013-05-20 12:58:51 -0400
commit9ccb3c0611aaa4f6796f34067b604718908f1c82 (patch)
treea8514203aef39376f88edfb20116659c3217967c /modules/textadept/editing.lua
parent9d9b745b3103e95b7f2b8ec8a65c149f61b7e4bb (diff)
downloadtextadept-9ccb3c0611aaa4f6796f34067b604718908f1c82.tar.gz
textadept-9ccb3c0611aaa4f6796f34067b604718908f1c82.zip
Fix caret placement in block comment/uncomment.
Thanks to Richard Philips.
Diffstat (limited to 'modules/textadept/editing.lua')
-rw-r--r--modules/textadept/editing.lua13
1 files changed, 8 insertions, 5 deletions
diff --git a/modules/textadept/editing.lua b/modules/textadept/editing.lua
index 896d4b0d..2958ad1a 100644
--- a/modules/textadept/editing.lua
+++ b/modules/textadept/editing.lua
@@ -278,10 +278,9 @@ function M.block_comment(prefix)
prefix = prefix or M.comment_string[buffer:get_lexer(true)]
if not prefix then return end
local anchor, pos = buffer.selection_start, buffer.selection_end
- local s = buffer:line_from_position(anchor)
- local e = buffer:line_from_position(pos)
- local mlines = s ~= e
- if mlines and pos == buffer:position_from_line(e) then e = e - 1 end
+ local s, e = buffer:line_from_position(anchor), buffer:line_from_position(pos)
+ if s ~= e and pos == buffer:position_from_line(e) then e = e - 1 end
+ anchor, pos = buffer.line_end_position[s] - anchor, buffer.length - pos
buffer:begin_undo_action()
for line = s, e do
local pos = buffer:position_from_line(line)
@@ -295,7 +294,11 @@ function M.block_comment(prefix)
end
end
buffer:end_undo_action()
- if mlines then buffer:set_sel(anchor, pos) else buffer:goto_pos(pos) end
+ anchor, pos = buffer.line_end_position[s] - anchor, buffer.length - pos
+ if anchor < buffer:position_from_line(s) then
+ anchor = buffer:position_from_line(s) -- stay on the first line
+ end
+ if s ~= e then buffer:set_sel(anchor, pos) else buffer:goto_pos(pos) end
end
---