diff options
author | 2020-03-17 15:08:26 -0400 | |
---|---|---|
committer | 2020-03-17 15:08:26 -0400 | |
commit | 92bf8d4488d50e31b32d593ca78973b557cc8df7 (patch) | |
tree | 26dd12465821ddae77f0e7d06918010d98f06d5b | |
parent | 573c184b20dac1e8d5d5b659a04a2ea9744d6352 (diff) |
Align block comments by column if possible, not indent.
-rw-r--r-- | modules/textadept/editing.lua | 3 | ||||
-rw-r--r-- | test/test.lua | 14 |
2 files changed, 10 insertions, 7 deletions
diff --git a/modules/textadept/editing.lua b/modules/textadept/editing.lua index bc5d8ffa..3b45cee9 100644 --- a/modules/textadept/editing.lua +++ b/modules/textadept/editing.lua @@ -319,9 +319,12 @@ function M.block_comment() local s, e = buffer:line_from_position(anchor), buffer:line_from_position(pos) local ignore_last_line = s ~= e and pos == buffer:position_from_line(e) anchor, pos = buffer.line_end_position[s] - anchor, buffer.length - pos + local column = math.huge 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 buffer:insert_text(p, prefix) diff --git a/test/test.lua b/test/test.lua index 6ba7c9d2..a584cacc 100644 --- a/test/test.lua +++ b/test/test.lua @@ -1413,7 +1413,7 @@ function test_editing_block_comment_lines() assert_equal(buffer:get_text(), table.concat({ '', '--local foo = "bar"', - ' --local baz = "quux"', + '-- local baz = "quux"', '' }, '\n')) assert_equal(buffer.selection_start, buffer:position_from_line(LINE(2)) + offset + 2) @@ -1438,16 +1438,16 @@ function test_editing_block_comment() buffer:set_lexer('ansi_c') buffer:set_text(table.concat({ '', - 'const char *foo = "bar";', - ' const char *baz = "quux";', + ' const char *foo = "bar";', + 'const char *baz = "quux";', '' }, '\n')) buffer:set_sel(buffer:position_from_line(LINE(2)), buffer:position_from_line(LINE(4))) textadept.editing.block_comment() assert_equal(buffer:get_text(), table.concat({ '', - '/*const char *foo = "bar";*/', - ' /*const char *baz = "quux";*/', + ' /*const char *foo = "bar";*/', + '/*const char *baz = "quux";*/', '' }, '\n')) assert_equal(buffer.selection_start, buffer:position_from_line(LINE(2)) + 2) @@ -1455,8 +1455,8 @@ function test_editing_block_comment() textadept.editing.block_comment() -- uncomment assert_equal(buffer:get_text(), table.concat({ '', - 'const char *foo = "bar";', - ' const char *baz = "quux";', + ' const char *foo = "bar";', + 'const char *baz = "quux";', '' }, '\n')) assert_equal(buffer.selection_start, buffer:position_from_line(LINE(2))) |