bugfix: restore state after C-f (find)

This commit is contained in:
Kartik K. Agaram 2022-06-03 13:59:40 -07:00
parent ac83252684
commit 06e6ecdf8f
2 changed files with 14 additions and 8 deletions

View File

@ -77,7 +77,7 @@ Next_history = 1
-- search
Search_term = nil
Search_text = nil
Search_backup_cursor1 = nil -- where to position the cursor if search term was not found
Search_backup = nil -- stuff to restore when cancelling search
end -- App.initialize_globals
@ -249,11 +249,13 @@ function App.keychord_pressed(chord)
if chord == 'escape' then
Search_term = nil
Search_text = nil
Cursor1 = Search_backup_cursor1
Search_backup_cursor1 = nil
Cursor1 = Search_backup.cursor
Screen_top1 = Search_backup.screen_top
Search_backup = nil
elseif chord == 'return' then
Search_term = nil
Search_text = nil
Search_backup = nil
elseif chord == 'backspace' then
local len = utf8.len(Search_term)
local byte_offset = utf8.offset(Search_term, len)
@ -268,7 +270,7 @@ function App.keychord_pressed(chord)
return
elseif chord == 'C-f' then
Search_term = ''
Search_backup_cursor1 = {line=Cursor1.line, pos=Cursor1.pos}
Search_backup = {cursor={line=Cursor1.line, pos=Cursor1.pos}, screen_top={line=Screen_top1.line, pos=Screen_top1.pos}}
assert(Search_text == nil)
elseif chord == 'C-=' then
Font_height = Font_height+2

View File

@ -153,8 +153,10 @@ function Text.search_next()
end
end
if pos == nil then
Cursor1.line = Search_backup_cursor1.line
Cursor1.pos = Search_backup_cursor1.pos
Cursor1.line = Search_backup.cursor.line
Cursor1.pos = Search_backup.cursor.pos
Screen_top1.line = Search_backup.screen_top.line
Screen_top1.pos = Search_backup.screen_top.pos
end
if Text.lt1(Cursor1, Screen_top1) or Text.lt1(Screen_bottom1, Cursor1) then
Screen_top1.line = Cursor1.line
@ -191,8 +193,10 @@ function Text.search_previous()
end
end
if pos == nil then
Cursor1.line = Search_backup_cursor1.line
Cursor1.pos = Search_backup_cursor1.pos
Cursor1.line = Search_backup.cursor.line
Cursor1.pos = Search_backup.cursor.pos
Screen_top1.line = Search_backup.screen_top.line
Screen_top1.pos = Search_backup.screen_top.pos
end
if Text.lt1(Cursor1, Screen_top1) or Text.lt1(Screen_bottom1, Cursor1) then
Screen_top1.line = Cursor1.line