Merge lines.love

This commit is contained in:
Kartik K. Agaram 2023-03-17 10:55:33 -07:00
commit cd144ec626
5 changed files with 54 additions and 9 deletions

View File

@ -813,7 +813,7 @@ function populate_errors_column(column)
pane.line_height = Line_height
pane.em = Em
pane.editable = false
edit.fixup_cursor(pane)
edit.check_locs(pane)
pane.title = '(do not edit)'
Text.redraw_all(pane)
table.insert(column, pane)

View File

@ -112,10 +112,32 @@ function edit.initialize_state(top, left, right, font_height, line_height) -- c
return result
end -- App.initialize_state
function edit.fixup_cursor(State)
function edit.check_locs(State)
-- if State is inconsistent (i.e. file changed by some other program),
-- throw away all cursor state entirely
if edit.invalid1(State, State.screen_top1)
or edit.invalid1(State, State.cursor1)
or not edit.cursor_on_text(State)
or not Text.le1(State.screen_top1, State.cursor1) then
State.screen_top1 = {line=1, pos=1}
edit.put_cursor_on_first_text_line(State)
end
end
function edit.invalid1(State, loc1)
return loc1.line > #State.lines
or loc1.pos > #State.lines[loc1.line].data
end
function edit.cursor_on_text(State)
return State.cursor1.line <= #State.lines
and State.lines[State.cursor1.line].mode == 'text'
end
function edit.put_cursor_on_first_text_line(State)
for i,line in ipairs(State.lines) do
if line.mode == 'text' then
State.cursor1.line = i
State.cursor1 = {line=i, pos=1}
break
end
end

View File

@ -235,7 +235,7 @@ function load_pane(id)
result.line_height = Line_height
result.em = Em
result.editable = false
edit.fixup_cursor(result)
edit.check_locs(result)
Text.redraw_all(result)
return result
end
@ -883,7 +883,7 @@ function search_next()
for current_pane_index=Cursor_pane.row+1,#Surface[Cursor_pane.col] do
local pane = Surface[Cursor_pane.col][current_pane_index]
pane.cursor1 = {line=1, pos=1}
edit.fixup_cursor(pane)
edit.check_locs(pane)
pane.screen_top1 = {line=1, pos=1}
if search_next_in_pane(pane) then
Cursor_pane.row = current_pane_index
@ -896,7 +896,7 @@ function search_next()
while true do
for current_pane_index,pane in ipairs(Surface[current_column_index]) do
pane.cursor1 = {line=1, pos=1}
edit.fixup_cursor(pane)
edit.check_locs(pane)
pane.screen_top1 = {line=1, pos=1}
if search_next_in_pane(pane) then
Cursor_pane = {col=current_column_index, row=current_pane_index}
@ -924,7 +924,7 @@ function search_next()
local pane = Surface[Cursor_pane.col][Cursor_pane.row]
local old_cursor = pane.cursor1
pane.cursor1 = {line=1, pos=1}
edit.fixup_cursor(pane)
edit.check_locs(pane)
pane.screen_top1 = {line=1, pos=1}
if search_next_in_pane(pane) then
if Text.lt1(pane.cursor1, old_cursor) then

View File

@ -88,6 +88,7 @@ function source.initialize_edit_side()
Editor_state.screen_top1 = {line=1, pos=1}
Editor_state.cursor1 = {line=1, pos=1}
end
edit.check_locs(Editor_state)
-- We currently start out with side B collapsed.
-- Other options:

View File

@ -115,10 +115,32 @@ function edit.initialize_state(top, left, right, font_height, line_height) -- c
return result
end -- App.initialize_state
function edit.fixup_cursor(State)
function edit.check_locs(State)
-- if State is inconsistent (i.e. file changed by some other program),
-- throw away all cursor state entirely
if edit.invalid1(State, State.screen_top1)
or edit.invalid1(State, State.cursor1)
or not edit.cursor_on_text(State)
or not Text.le1(State.screen_top1, State.cursor1) then
State.screen_top1 = {line=1, pos=1}
edit.put_cursor_on_first_text_line(State)
end
end
function edit.invalid1(State, loc1)
return loc1.line > #State.lines
or loc1.pos > #State.lines[loc1.line].data
end
function edit.cursor_on_text(State)
return State.cursor1.line <= #State.lines
and State.lines[State.cursor1.line].mode == 'text'
end
function edit.put_cursor_on_first_text_line(State)
for i,line in ipairs(State.lines) do
if line.mode == 'text' then
State.cursor1.line = i
State.cursor1 = {line=i, pos=1}
break
end
end