revert selection logic to before commit 3ffc2ed8f

We still have a failing test, but now it's the one we introduced in
commit 3ffc2ed8f.
This commit is contained in:
Kartik K. Agaram 2022-06-20 13:12:29 -07:00
parent 978c143397
commit 0d1e6aacd9
3 changed files with 12 additions and 8 deletions

View File

@ -391,7 +391,6 @@ function App.mousereleased(x,y, button)
end
end
-- don't depend on state of Selection1; use keychord_pressed for that
function App.textinput(t)
for _,line in ipairs(Lines) do line.y = nil end -- just in case we scroll
if Search_term then
@ -551,9 +550,6 @@ function App.keychord_pressed(chord)
for _,line in ipairs(Lines) do line.y = nil end -- just in case we scroll
Text.keychord_pressed(chord)
end
if not App.shift_down() and chord ~= 'C-c' then
Selection1 = {}
end
end
function App.keyreleased(key, scancode)

View File

@ -137,12 +137,14 @@ function Text.compute_fragments(line, line_width)
end
end
-- don't depend on state of Selection1; use keychord_pressed for that
function Text.textinput(t)
if App.mouse_down(1) then return end
assert(not App.ctrl_down())
if App.alt_down() then return end
assert(not App.cmd_down())
if Selection1.line then
Text.delete_selection()
end
local before = snapshot(Cursor1.line)
--? print(Screen_top1.line, Screen_top1.pos, Cursor1.line, Cursor1.pos, Screen_bottom1.line, Screen_bottom1.pos)
Text.insert_at_cursor(t)
@ -267,8 +269,10 @@ function Text.keychord_pressed(chord)
--== shortcuts that move the cursor
elseif chord == 'left' then
Text.left()
Selection1 = {}
elseif chord == 'right' then
Text.right()
Selection1 = {}
elseif chord == 'S-left' then
if Selection1.line == nil then
Selection1 = {line=Cursor1.line, pos=Cursor1.pos}
@ -282,8 +286,10 @@ function Text.keychord_pressed(chord)
-- C- hotkeys reserved for drawings, so we'll use M-
elseif chord == 'M-left' then
Text.word_left()
Selection1 = {}
elseif chord == 'M-right' then
Text.word_right()
Selection1 = {}
elseif chord == 'M-S-left' then
if Selection1.line == nil then
Selection1 = {line=Cursor1.line, pos=Cursor1.pos}
@ -310,8 +316,10 @@ function Text.keychord_pressed(chord)
Cursor1.pos = utf8.len(Lines[Cursor1.line].data) + 1
elseif chord == 'up' then
Text.up()
Selection1 = {}
elseif chord == 'down' then
Text.down()
Selection1 = {}
elseif chord == 'S-up' then
if Selection1.line == nil then
Selection1 = {line=Cursor1.line, pos=Cursor1.pos}
@ -324,8 +332,10 @@ function Text.keychord_pressed(chord)
Text.down()
elseif chord == 'pageup' then
Text.pageup()
Selection1 = {}
elseif chord == 'pagedown' then
Text.pagedown()
Selection1 = {}
elseif chord == 'S-pageup' then
if Selection1.line == nil then
Selection1 = {line=Cursor1.line, pos=Cursor1.pos}
@ -337,9 +347,6 @@ function Text.keychord_pressed(chord)
end
Text.pagedown()
end
if Selection1.line and not App.shift_down() then
Text.delete_selection()
end
end
function Text.insert_return()

View File

@ -1335,6 +1335,7 @@ function test_undo_restores_selection()
check_nil(Selection1.line, 'F - test_undo_restores_selection/baseline:selection')
-- undo
App.run_after_keychord('C-z')
App.run_after_keychord('C-z')
-- selection is restored
check_eq(Selection1.line, 1, 'F - test_undo_restores_selection/line')
check_eq(Selection1.pos, 2, 'F - test_undo_restores_selection/pos')