Skip to content

Commit

Permalink
Fixed incorrect bitwise operation.
Browse files Browse the repository at this point in the history
This consolidates changes from r3135 and r3149 and fixes an additional restore selection case.
  • Loading branch information
orbitalquark committed Jun 12, 2021
1 parent 46eb36c commit 62906b8
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion core/events.lua
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ end
-- Emits events prior to and after replacing buffer text.
M.connect(M.MODIFIED, function(position, mod, text, length)
if mod & (DELETE | INSERT) == 0 or length ~= buffer.length then return end
if mod & (INSERT | UNDOREDO) > 0 then
if mod & (INSERT | UNDOREDO) == INSERT | UNDOREDO then
-- Cannot emit BUFFER_AFTER_REPLACE_TEXT here because Scintilla will do things like update
-- the selection afterwards, which could undo what event handlers do.
events.connect(events.UPDATE_UI, emit_after_replace_text)
Expand Down
5 changes: 1 addition & 4 deletions core/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -375,10 +375,7 @@ local function restore_buffer_state()
view.x_offset = buffer._x_offset or 0
end
events.connect(events.BUFFER_AFTER_SWITCH, restore_buffer_state)
events.connect(events.BUFFER_AFTER_REPLACE_TEXT, function()
local anchor, pos = buffer._anchor or 0, buffer._current_pos or 0
if anchor <= buffer.length and pos <= buffer.length then restore_buffer_state() end
end)
events.connect(events.BUFFER_AFTER_REPLACE_TEXT, restore_buffer_state)

-- Updates titlebar and statusbar.
local function update_bars()
Expand Down
5 changes: 3 additions & 2 deletions test/test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2144,7 +2144,7 @@ function test_editing_filter_through()
textadept.editing.filter_through('sort')
assert_equal(buffer:get_text(), '3|baz\n1|foo\n1|foo\n4|quux\n5|foobar\n2|bar\n')
buffer:undo()
-- Test multiple selection.
-- Test rectangular selection.
buffer:set_text('987654321\n123456789\n')
buffer.rectangular_selection_anchor = 4
buffer.rectangular_selection_caret = 17
Expand All @@ -2154,8 +2154,9 @@ function test_editing_filter_through()
assert_equal(buffer.rectangular_selection_caret, 17)
buffer:undo()
assert_equal(buffer:get_text(), '987654321\n123456789\n')
-- Test rectangular selection.
-- Test multiple selection.
buffer:set_text('foo\n\tfoo\n\t\tfoo\nfoo')
buffer:goto_pos(1)
textadept.editing.select_word()
textadept.editing.select_word()
textadept.editing.select_word()
Expand Down

0 comments on commit 62906b8

Please sign in to comment.