From 91f18298fb33acfbbf9c26bef71bd940ffccba80 Mon Sep 17 00:00:00 2001 From: mitchell Date: Fri, 1 Oct 2021 16:11:48 -0400 Subject: Fixed uncommenting comments that are not initially aligned. --- docs/changelog.md | 1 + modules/textadept/editing.lua | 4 ++-- test/test.lua | 22 ++++++++++++++++++++++ 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 -- cgit v1.2.3