aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--THANKS.md1
-rw-r--r--modules/textadept/editing.lua13
2 files changed, 9 insertions, 5 deletions
diff --git a/THANKS.md b/THANKS.md
index 2976da76..ec456bc8 100644
--- a/THANKS.md
+++ b/THANKS.md
@@ -22,6 +22,7 @@ Textadept the amazing editor that it is today.
* Nils Nordman
* Patrick McMorris
* Pedro Andres Aranda Gutierrez
+* Richard Philips
* Robert Gieseke
* Russell Dickenson
* Ryan Pusztai
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
---