aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar mitchell <none@none>2021-10-01 16:11:48 -0400
committerGravatar mitchell <none@none>2021-10-01 16:11:48 -0400
commit91f18298fb33acfbbf9c26bef71bd940ffccba80 (patch)
treefcfe96ab3f5443b1ac9ec87925bce14451cb0e5f
parent45bdbe2d13e5840c25dfadc27b49288ba486e729 (diff)
Fixed uncommenting comments that are not initially aligned.
-rw-r--r--docs/changelog.md1
-rw-r--r--modules/textadept/editing.lua4
-rw-r--r--test/test.lua22
3 files changed, 25 insertions, 2 deletions
diff --git a/docs/changelog.md b/docs/changelog.md
index bc9c4f54..51928209 100644
--- a/docs/changelog.md
+++ b/docs/changelog.md
@@ -20,6 +20,7 @@ Bugfixes:
* Fixed Windows directory typos in the manual.
* Prevent running the command entry while in the command entry.
+* Fixed uncommenting comments that are not initially aligned.
* Scintilla: Fixed display of fold lines when wrapped so they are only drawn once per line.
* Scintilla: Fixed crash with too many subexpressions in regex searches.
* Scintilla: Fixed lack of display of underscores in some monospaced fonts on Linux.
diff --git a/modules/textadept/editing.lua b/modules/textadept/editing.lua
index c17d35e9..d115d1e1 100644
--- a/modules/textadept/editing.lua
+++ b/modules/textadept/editing.lua
@@ -360,10 +360,10 @@ function M.toggle_comment()
buffer:begin_undo_action()
for line = s, not ignore_last_line and e or e - 1 do
local p = buffer.line_indent_position[line]
- column = math.min(buffer.column[p], column)
- p = buffer:find_column(line, column)
local uncomment = buffer:text_range(p, p + #prefix) == prefix
if not uncomment then
+ column = math.min(buffer.column[p], column)
+ p = buffer:find_column(line, column)
buffer:insert_text(p, prefix)
if suffix ~= '' then buffer:insert_text(buffer.line_end_position[line], suffix) end
else
diff --git a/test/test.lua b/test/test.lua
index 6356ee1c..9767eaa8 100644
--- a/test/test.lua
+++ b/test/test.lua
@@ -1788,6 +1788,28 @@ function test_editing_toggle_comment_lines()
buffer:undo() -- comment
buffer:undo() -- uncomment
assert_equal(buffer:get_text(), text) -- verify atomic undo
+ -- LuaFormatter off
+ buffer:set_text(table.concat({
+ '--foo',
+ ' --foo'
+ }, '\n'))
+ -- LuaFormatter on
+ offset = 2
+ buffer:select_all()
+ textadept.editing.toggle_comment()
+ -- LuaFormatter off
+ assert_equal(buffer:get_text(), table.concat({
+ 'foo',
+ ' foo'
+ }, '\n'))
+ -- LuaFormatter on
+ textadept.editing.toggle_comment()
+ -- LuaFormatter off
+ assert_equal(buffer:get_text(), table.concat({
+ '--foo',
+ '-- foo'
+ }, '\n'))
+ -- LuaFormatter on
buffer:close(true)
end