bugfix: don't process most keys if cursor is out of view
I think the only situation this can happen is after pressing C-a to select a file (that doesn't fit on screen). But it's important for potential forks, e.g. positioning editors on infinite surfaces.
This commit is contained in:
parent
a6b9cd94be
commit
54242d9d07
23
edit.lua
23
edit.lua
|
@ -330,21 +330,32 @@ function edit.text_input(Editor, t)
|
|||
if Editor.search_term then
|
||||
Editor.search_term = Editor.search_term..t
|
||||
Text.search_next(Editor)
|
||||
elseif Editor.cursor.mode == 'drawing' and Editor.current_drawing_mode == 'name' then
|
||||
return
|
||||
end
|
||||
if edit.to_coord(Editor, Editor.cursor) then return end -- cursor is off screen
|
||||
-- to be precise, the top-left corner of the cursor is off screen
|
||||
-- for drawings the cursor is large, which can still be a bit strange
|
||||
-- large selections can also be strange, though the actual cursor would still be small
|
||||
if Editor.cursor.mode == 'drawing' and Editor.current_drawing_mode == 'name' then
|
||||
-- TODO: there's a bug here where the point being named may be off screen
|
||||
-- To hit that bug you'd have to press C-n to go into point naming mode
|
||||
-- while the cursor is on screen, then move the page somehow without going
|
||||
-- out of naming mode.
|
||||
local before = snapshot(Editor, Editor.cursor.line)
|
||||
local drawing = Editor.lines[Editor.cursor.line]
|
||||
local p = drawing.points[drawing.pending.target_point]
|
||||
p.name = p.name..t
|
||||
record_undo_event(Editor, {before=before, after=snapshot(Editor, Editor.cursor.line)})
|
||||
else
|
||||
-- why is this here?
|
||||
Text.text_input(Editor, t)
|
||||
end
|
||||
schedule_save(Editor)
|
||||
end
|
||||
|
||||
function edit.keychord_press(Editor, chord, key)
|
||||
local cursor_on_screen = edit.to_coord(Editor, Editor.cursor)
|
||||
if Editor.selection1.line and Editor.cursor.mode == 'text' and
|
||||
cursor_on_screen and
|
||||
-- printable character created using shift key => delete selection
|
||||
-- (we're not creating any ctrl-shift- or alt-shift- combinations using regular/printable keys)
|
||||
(not shift_down() or utf8.len(key) == 1) and
|
||||
|
@ -411,7 +422,7 @@ function edit.keychord_press(Editor, chord, key)
|
|||
schedule_save(Editor)
|
||||
end
|
||||
-- clipboard
|
||||
elseif chord == 'C-a' then
|
||||
elseif chord == 'C-a' and cursor_on_screen then
|
||||
Editor.selection1 = {line=1, pos=1}
|
||||
Editor.cursor = {mode='text', line=#Editor.lines, pos=utf8.len(Editor.lines[#Editor.lines].data)+1}
|
||||
elseif chord == 'C-c' then
|
||||
|
@ -419,13 +430,13 @@ function edit.keychord_press(Editor, chord, key)
|
|||
if s then
|
||||
love.system.setClipboardText(s)
|
||||
end
|
||||
elseif chord == 'C-x' then
|
||||
elseif chord == 'C-x' and cursor_on_screen then
|
||||
local s = Text.cut_selection(Editor, Editor.left, Editor.right)
|
||||
if s then
|
||||
love.system.setClipboardText(s)
|
||||
end
|
||||
schedule_save(Editor)
|
||||
elseif chord == 'C-v' then
|
||||
elseif chord == 'C-v' and cursor_on_screen then
|
||||
-- We don't have a good sense of when to scroll, so we'll be conservative
|
||||
-- and sometimes scroll when we didn't quite need to.
|
||||
local before_line = Editor.cursor.line
|
||||
|
@ -478,7 +489,7 @@ function edit.keychord_press(Editor, chord, key)
|
|||
end
|
||||
end
|
||||
schedule_save(Editor)
|
||||
else
|
||||
elseif cursor_on_screen then
|
||||
Text.keychord_press(Editor, chord)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue