diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/handlers.lua | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/core/handlers.lua b/core/handlers.lua index 1fcdb26d..2a343dd3 100644 --- a/core/handlers.lua +++ b/core/handlers.lua @@ -138,8 +138,8 @@ add_handler_function('char_added', function(char) -- auto-indent on return if char ~= '\n' then return end local buffer = buffer - local pos = buffer.current_pos - local curr_line = buffer:line_from_position(pos) + local anchor, caret = buffer.anchor, buffer.current_pos + local curr_line = buffer:line_from_position(caret) local last_line = curr_line - 1 while last_line >= 0 and #buffer:get_line(last_line) == 1 do last_line = last_line - 1 @@ -149,7 +149,15 @@ add_handler_function('char_added', local s = buffer.line_indent_position[curr_line] buffer.line_indentation[curr_line] = indentation local e = buffer.line_indent_position[curr_line] - buffer:goto_pos(pos + e - s) + local diff = e - s + if e > s then -- move selection on + if anchor >= s then anchor = anchor + diff end + if caret >= s then caret = caret + diff end + elseif e < s then -- move selection back + if anchor >= e then anchor = anchor >= s and anchor + diff or e end + if caret >= e then caret = caret >= s and caret + diff or e end + end + buffer:set_sel(anchor, caret) end end) |