about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2023-06-08 01:12:38 -0700
committerKartik K. Agaram <vc@akkartik.com>2023-06-08 01:12:38 -0700
commitfdb2172843ae7bd3acfb8fcb0f02b3dede301857 (patch)
treeb1a294cb0436738a0b78a09eb4c42d79524dec28
parente8a5faaa4cbdb6a9f15ad4edf1ca4e86879edf19 (diff)
parent14c08f9bd9a45d2f05727ea47b128afdbdff1d24 (diff)
downloadtext.love-fdb2172843ae7bd3acfb8fcb0f02b3dede301857.tar.gz
Merge lines.love
-rw-r--r--Manual_tests.md4
-rw-r--r--edit.lua12
-rw-r--r--run.lua15
3 files changed, 24 insertions, 7 deletions
diff --git a/Manual_tests.md b/Manual_tests.md
index 236cd27..dd7aeb7 100644
--- a/Manual_tests.md
+++ b/Manual_tests.md
@@ -5,6 +5,10 @@ record those here.
 
 Initializing settings:
   - delete app settings, start; window opens running the text editor
+  - run with a filename on commandline, scroll around, quit; restart without a filename; window opens running the text editor in same position+dimensions
+  - run with a filename on commandline, scroll around, quit; restart with same filename; window opens running the text editor in same position+dimensions
+  - run with a filename on commandline, scroll around, quit; restart with new filename; window opens new filename with cursor up top
+  - run editor, scroll around, move cursor to end of some line, quit; restart with new filename; window opens running the text editor in same position+dimensions
   - quit while running the text editor, restart; window opens running the text editor in same position+dimensions
   - quit while editing source (color; no selection), restart; window opens editing source in same position+dimensions
   - start out running the text editor, move window, press ctrl+e twice; window is running text editor in same position+dimensions
diff --git a/edit.lua b/edit.lua
index 8b5cbf7..fd7448b 100644
--- a/edit.lua
+++ b/edit.lua
@@ -73,7 +73,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 Text.le1(State.screen_top1, State.cursor1) then
     State.screen_top1 = {line=1, pos=1}
     State.cursor1 = {line=1, pos=1}
@@ -87,6 +87,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
+
 -- return y drawn until
 function edit.draw(State)
   App.color(Text_color)
diff --git a/run.lua b/run.lua
index 4c8968a..b56a0d2 100644
--- a/run.lua
+++ b/run.lua
@@ -19,7 +19,7 @@ function run.initialize(arg)
     run.initialize_default_settings()
   end
 
-  if #arg > 0 then
+  if #arg > 0 and Editor_state.filename ~= absolutize(arg[1]) then
     Editor_state.filename = arg[1]
     load_from_disk(Editor_state)
     Text.redraw_all(Editor_state)
@@ -154,19 +154,22 @@ function run.settings()
   if Current_app == 'run' then
     Settings.x, Settings.y, Settings.displayindex = App.screen.position()
   end
-  local filename = Editor_state.filename
-  if is_relative_path(filename) then
-    filename = love.filesystem.getWorkingDirectory()..'/'..filename  -- '/' should work even on Windows
-  end
   return {
     x=Settings.x, y=Settings.y, displayindex=Settings.displayindex,
     width=App.screen.width, height=App.screen.height,
     font_height=Editor_state.font_height,
-    filename=filename,
+    filename=absolutize(Editor_state.filename),
     screen_top=Editor_state.screen_top1, cursor=Editor_state.cursor1
   }
 end
 
+function absolutize(path)
+  if is_relative_path(path) then
+    return love.filesystem.getWorkingDirectory()..'/'..path  -- '/' should work even on Windows
+  end
+  return path
+end
+
 function run.mouse_press(x,y, mouse_button)
   Cursor_time = 0  -- ensure cursor is visible immediately after it moves
   return edit.mouse_press(Editor_state, x,y, mouse_button)
4:06 -0700 5211' href='/akkartik/mu/commit/html/subx/034compute_segment_address.cc.html?h=main&id=52daf0722f7f4ad9d3f29e3cbbbaddde066f49f3'>52daf072 ^
91624dba ^
c504ca56 ^
52daf072 ^



91624dba ^
52daf072 ^











c504ca56 ^

52daf072 ^

91624dba ^
52daf072 ^
c504ca56 ^


52daf072 ^


695f9bf8 ^
c504ca56 ^
52daf072 ^

c504ca56 ^
52daf072 ^




c504ca56 ^

52daf072 ^



91624dba ^
52daf072 ^
c504ca56 ^

52daf072 ^


























608a7fa8 ^



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148