From 6e2137c5b6bde9c84e96cd919fce38581558b917 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 16 Sep 2023 22:39:51 -0700 Subject: bugfix to the helper I added yesterday --- edit.lua | 1 + source_edit.lua | 1 + 2 files changed, 2 insertions(+) diff --git a/edit.lua b/edit.lua index d30dbdc..b9bd9c4 100644 --- a/edit.lua +++ b/edit.lua @@ -113,6 +113,7 @@ function edit.check_locs(State) or not edit.cursor_on_text(State) or not Text.le1(State.screen_top1, State.cursor1) then State.screen_top1 = {line=1, pos=1} + State.cursor1 = {line=1, pos=1} edit.put_cursor_on_next_text_line(State) end end diff --git a/source_edit.lua b/source_edit.lua index 506aa41..5c77758 100644 --- a/source_edit.lua +++ b/source_edit.lua @@ -115,6 +115,7 @@ function edit.check_locs(State) or not edit.cursor_on_text(State) or not Text.le1(State.screen_top1, State.cursor1) then State.screen_top1 = {line=1, pos=1} + State.cursor1 = {line=1, pos=1} edit.put_cursor_on_next_text_line(State) end end -- cgit 1.4.1-2-gfad0 From 9241fedf3a098ceea1b4d5e408c59ae31d75be3f Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 16 Sep 2023 22:40:46 -0700 Subject: port an old fix to source editor --- source_edit.lua | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/source_edit.lua b/source_edit.lua index 5c77758..d2cd7d9 100644 --- a/source_edit.lua +++ b/source_edit.lua @@ -111,7 +111,7 @@ 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 edit.invalid_cursor1(State) or not edit.cursor_on_text(State) or not Text.le1(State.screen_top1, State.cursor1) then State.screen_top1 = {line=1, pos=1} @@ -127,6 +127,16 @@ function edit.invalid1(State, loc1) return loc1.pos > #State.lines[loc1.line].data end +-- cursor loc in particular differs from other locs in one way: +-- pos might occur just after end of line +function edit.invalid_cursor1(State) + local cursor1 = State.cursor1 + if cursor1.line > #State.lines then return true end + local l = State.lines[cursor1.line] + if l.mode ~= 'text' then return false end -- pos is irrelevant to validity for a drawing line + return cursor1.pos > #State.lines[cursor1.line].data + 1 +end + function edit.cursor_on_text(State) return State.cursor1.line <= #State.lines and State.lines[State.cursor1.line].mode == 'text' -- cgit 1.4.1-2-gfad0 From c43d884b6ffb94803bee9f9e788e4b3a2f74f23b Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 16 Sep 2023 22:41:55 -0700 Subject: indent --- edit.lua | 16 ++++++++-------- source_edit.lua | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/edit.lua b/edit.lua index b9bd9c4..45588df 100644 --- a/edit.lua +++ b/edit.lua @@ -142,14 +142,14 @@ end function edit.put_cursor_on_next_text_line(State) while true do - if State.cursor1.line >= #State.lines then - break - end - if State.lines[State.cursor1.line].mode == 'text' then - break - end - State.cursor1.line = State.cursor1.line+1 - State.cursor1.pos = 1 + if State.cursor1.line >= #State.lines then + break + end + if State.lines[State.cursor1.line].mode == 'text' then + break + end + State.cursor1.line = State.cursor1.line+1 + State.cursor1.pos = 1 end end diff --git a/source_edit.lua b/source_edit.lua index d2cd7d9..310853a 100644 --- a/source_edit.lua +++ b/source_edit.lua @@ -144,14 +144,14 @@ end function edit.put_cursor_on_next_text_line(State) while true do - if State.cursor1.line >= #State.lines then - break - end - if State.lines[State.cursor1.line].mode == 'text' then - break - end - State.cursor1.line = State.cursor1.line+1 - State.cursor1.pos = 1 + if State.cursor1.line >= #State.lines then + break + end + if State.lines[State.cursor1.line].mode == 'text' then + break + end + State.cursor1.line = State.cursor1.line+1 + State.cursor1.pos = 1 end end -- cgit 1.4.1-2-gfad0