Merge lines.love
This commit is contained in:
commit
af0d177d57
|
@ -47,12 +47,6 @@ found anything amiss: http://akkartik.name/contact
|
|||
|
||||
* No support yet for right-to-left languages.
|
||||
|
||||
* Undo/redo may be sluggish in large files. Large files may grow sluggish in
|
||||
other ways. Works well in all circumstances with files under 50KB.
|
||||
|
||||
* If you kill the process, say by force-quitting because things things get
|
||||
sluggish, you can lose data.
|
||||
|
||||
* Can't scroll while selecting text with mouse.
|
||||
|
||||
* No scrollbars yet. That stuff is hard.
|
||||
|
|
4
edit.lua
4
edit.lua
|
@ -264,7 +264,7 @@ function edit.keychord_press(State, chord, key)
|
|||
-- (we're not creating any ctrl-shift- or alt-shift- combinations using regular/printable keys)
|
||||
(not App.shift_down() or utf8.len(key) == 1) and
|
||||
chord ~= 'C-a' and chord ~= 'C-c' and chord ~= 'C-x' and chord ~= 'backspace' and chord ~= 'delete' and chord ~= 'C-z' and chord ~= 'C-y' and not App.is_cursor_movement(key) then
|
||||
Text.delete_selection(State, State.left, State.right)
|
||||
Text.delete_selection_and_record_undo_event(State)
|
||||
end
|
||||
if State.search_term then
|
||||
if chord == 'escape' then
|
||||
|
@ -341,7 +341,7 @@ function edit.keychord_press(State, chord, key)
|
|||
App.set_clipboard(s)
|
||||
end
|
||||
elseif chord == 'C-x' then
|
||||
local s = Text.cut_selection(State, State.left, State.right)
|
||||
local s = Text.cut_selection_and_record_undo_event(State)
|
||||
if s then
|
||||
App.set_clipboard(s)
|
||||
end
|
||||
|
|
|
@ -79,14 +79,14 @@ function Text.mouse_pos(State)
|
|||
return screen_bottom1.line, Text.pos_at_end_of_screen_line(State, screen_bottom1)
|
||||
end
|
||||
|
||||
function Text.cut_selection(State)
|
||||
function Text.cut_selection_and_record_undo_event(State)
|
||||
if State.selection1.line == nil then return end
|
||||
local result = Text.selection(State)
|
||||
Text.delete_selection(State)
|
||||
Text.delete_selection_and_record_undo_event(State)
|
||||
return result
|
||||
end
|
||||
|
||||
function Text.delete_selection(State)
|
||||
function Text.delete_selection_and_record_undo_event(State)
|
||||
if State.selection1.line == nil then return end
|
||||
local minl,maxl = minmax(State.selection1.line, State.cursor1.line)
|
||||
local before = snapshot(State, minl, maxl)
|
||||
|
|
|
@ -190,6 +190,7 @@ function edit.draw(State, hide_cursor, show_line_numbers)
|
|||
State.cursor1.line = State.cursor1.line+1
|
||||
end
|
||||
record_undo_event(State, {before=Drawing.before, after=snapshot(State, line_index-1, line_index+1)})
|
||||
Drawing.before = nil
|
||||
schedule_save(State)
|
||||
end,
|
||||
})
|
||||
|
@ -391,7 +392,7 @@ function edit.keychord_press(State, chord, key)
|
|||
-- (we're not creating any ctrl-shift- or alt-shift- combinations using regular/printable keys)
|
||||
(not App.shift_down() or utf8.len(key) == 1) and
|
||||
chord ~= 'C-a' and chord ~= 'C-c' and chord ~= 'C-x' and chord ~= 'backspace' and chord ~= 'delete' and chord ~= 'C-z' and chord ~= 'C-y' and not App.is_cursor_movement(key) then
|
||||
Text.delete_selection(State, State.left, State.right)
|
||||
Text.delete_selection_and_record_undo_event(State)
|
||||
end
|
||||
if State.search_term then
|
||||
if chord == 'escape' then
|
||||
|
@ -469,7 +470,7 @@ function edit.keychord_press(State, chord, key)
|
|||
App.set_clipboard(s)
|
||||
end
|
||||
elseif chord == 'C-x' then
|
||||
local s = Text.cut_selection(State, State.left, State.right)
|
||||
local s = Text.cut_selection_and_record_undo_event(State)
|
||||
if s then
|
||||
App.set_clipboard(s)
|
||||
end
|
||||
|
|
|
@ -83,14 +83,14 @@ function Text.mouse_pos(State)
|
|||
return screen_bottom1.line, Text.pos_at_end_of_screen_line(State, screen_bottom1)
|
||||
end
|
||||
|
||||
function Text.cut_selection(State)
|
||||
function Text.cut_selection_and_record_undo_event(State)
|
||||
if State.selection1.line == nil then return end
|
||||
local result = Text.selection(State)
|
||||
Text.delete_selection(State)
|
||||
Text.delete_selection_and_record_undo_event(State)
|
||||
return result
|
||||
end
|
||||
|
||||
function Text.delete_selection(State)
|
||||
function Text.delete_selection_and_record_undo_event(State)
|
||||
if State.selection1.line == nil then return end
|
||||
local minl,maxl = minmax(State.selection1.line, State.cursor1.line)
|
||||
local before = snapshot(State, minl, maxl)
|
||||
|
|
|
@ -248,7 +248,7 @@ function Text.keychord_press(State, chord)
|
|||
schedule_save(State)
|
||||
elseif chord == 'backspace' then
|
||||
if State.selection1.line then
|
||||
Text.delete_selection(State, State.left, State.right)
|
||||
Text.delete_selection_and_record_undo_event(State)
|
||||
schedule_save(State)
|
||||
return
|
||||
end
|
||||
|
@ -296,7 +296,7 @@ function Text.keychord_press(State, chord)
|
|||
schedule_save(State)
|
||||
elseif chord == 'delete' then
|
||||
if State.selection1.line then
|
||||
Text.delete_selection(State, State.left, State.right)
|
||||
Text.delete_selection_and_record_undo_event(State)
|
||||
schedule_save(State)
|
||||
return
|
||||
end
|
||||
|
|
4
text.lua
4
text.lua
|
@ -172,7 +172,7 @@ function Text.keychord_press(State, chord)
|
|||
schedule_save(State)
|
||||
elseif chord == 'backspace' then
|
||||
if State.selection1.line then
|
||||
Text.delete_selection(State, State.left, State.right)
|
||||
Text.delete_selection_and_record_undo_event(State)
|
||||
schedule_save(State)
|
||||
return
|
||||
end
|
||||
|
@ -215,7 +215,7 @@ function Text.keychord_press(State, chord)
|
|||
schedule_save(State)
|
||||
elseif chord == 'delete' then
|
||||
if State.selection1.line then
|
||||
Text.delete_selection(State, State.left, State.right)
|
||||
Text.delete_selection_and_record_undo_event(State)
|
||||
schedule_save(State)
|
||||
return
|
||||
end
|
||||
|
|
3
undo.lua
3
undo.lua
|
@ -1,8 +1,7 @@
|
|||
-- undo/redo by managing the sequence of events in the current session
|
||||
-- based on https://github.com/akkartik/mu1/blob/master/edit/012-editor-undo.mu
|
||||
|
||||
-- Incredibly inefficient; we make a copy of lines on every single keystroke.
|
||||
-- The hope here is that we're either editing small files or just reading large files.
|
||||
-- makes a copy of lines on every single keystroke; will be inefficient with really long lines.
|
||||
-- TODO: highlight stuff inserted by any undo/redo operation
|
||||
-- TODO: coalesce multiple similar operations
|
||||
|
||||
|
|
Loading…
Reference in New Issue