diff options
author | 2007-08-14 04:13:47 -0400 | |
---|---|---|
committer | 2007-08-14 04:13:47 -0400 | |
commit | f9db3ae35e605298dfb593c26610c34739c4f776 (patch) | |
tree | 5b645ff438e7c2a15768420aca68113dfccb109b /core/handlers.lua | |
parent | 96383b1dbbfe70ea0949075ead78f6f428d1eacd (diff) | |
download | textadept-f9db3ae35e605298dfb593c26610c34739c4f776.tar.gz textadept-f9db3ae35e605298dfb593c26610c34739c4f776.zip |
Fixed bug in maintaining indentation; core/handlers.lua
Adapted conditionals from SciTE to fix a bug where the caret is sometimes placed
incorrectly when trying to maintain indentation.
Diffstat (limited to 'core/handlers.lua')
-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) |