5 -- called both in tests and real run
6 function run
.initialize_globals()
7 -- tests currently mostly clear their own state
13 -- called only for real run
14 function run
.initialize(arg
)
19 run
.initialize_default_settings()
23 Editor_state
.filename
= arg
[1]
24 load_from_disk(Editor_state
)
25 Text
.redraw_all(Editor_state
)
26 Editor_state
.screen_top1
= {line
=1, pos
=1}
27 Editor_state
.cursor1
= {line
=1, pos
=1}
29 load_from_disk(Editor_state
)
30 Text
.redraw_all(Editor_state
)
32 edit
.check_locs(Editor_state
)
36 -- keep a few blank lines around: https://merveilles.town/@akkartik/110084833821965708
37 love
.window
.setTitle('lines.love - '..Editor_state
.filename
)
42 print('ignoring commandline args after '..arg
[1])
45 if rawget(_G
, 'jit') then
51 function run
.load_settings()
52 love
.graphics
.setFont(love
.graphics
.newFont(Settings
.font_height
))
53 -- determine default dimensions and flags
54 App
.screen
.width
, App
.screen
.height
, App
.screen
.flags
= App
.screen
.size()
55 -- set up desired window dimensions
56 App
.screen
.flags
.resizable
= true
57 App
.screen
.flags
.minwidth
= math
.min(App
.screen
.width
, 200)
58 App
.screen
.flags
.minheight
= math
.min(App
.screen
.height
, 200)
59 App
.screen
.width
, App
.screen
.height
= Settings
.width
, Settings
.height
60 App
.screen
.resize(App
.screen
.width
, App
.screen
.height
, App
.screen
.flags
)
61 App
.screen
.move(Settings
.x
, Settings
.y
, Settings
.displayindex
)
62 Editor_state
= edit
.initialize_state(Margin_top
, Margin_left
, App
.screen
.width
-Margin_right
, Settings
.font_height
, math
.floor(Settings
.font_height
*1.3))
63 Editor_state
.filename
= Settings
.filename
64 Editor_state
.screen_top1
= Settings
.screen_top
65 Editor_state
.cursor1
= Settings
.cursor
68 function run
.initialize_default_settings()
69 local font_height
= 20
70 love
.graphics
.setFont(love
.graphics
.newFont(font_height
))
71 run
.initialize_window_geometry(App
.width('m'))
72 Editor_state
= edit
.initialize_state(Margin_top
, Margin_left
, App
.screen
.width
-Margin_right
)
73 Editor_state
.font_height
= font_height
74 Editor_state
.line_height
= math
.floor(font_height
*1.3)
75 Settings
= run
.settings()
78 function run
.initialize_window_geometry(em_width
)
79 local os
= love
.system
.getOS()
80 if os
== 'Android' or os
== 'iOS' then
81 -- maximizing on iOS breaks text rendering: https://github.com/deltadaedalus/vudu/issues/7
82 -- no point second-guessing window dimensions on mobile
83 App
.screen
.width
, App
.screen
.height
, App
.screen
.flags
= App
.screen
.size()
87 App
.screen
.resize(0, 0) -- maximize
88 App
.screen
.width
, App
.screen
.height
, App
.screen
.flags
= App
.screen
.size()
89 -- shrink height slightly to account for window decoration
90 App
.screen
.height
= App
.screen
.height
-100
91 App
.screen
.width
= 40*em_width
92 App
.screen
.flags
.resizable
= true
93 App
.screen
.flags
.minwidth
= math
.min(App
.screen
.width
, 200)
94 App
.screen
.flags
.minheight
= math
.min(App
.screen
.height
, 200)
95 App
.screen
.resize(App
.screen
.width
, App
.screen
.height
, App
.screen
.flags
)
98 function run
.resize(w
, h
)
99 --? print(("Window resized to width: %d and height: %d."):format(w, h))
100 App
.screen
.width
, App
.screen
.height
= w
, h
101 Text
.redraw_all(Editor_state
)
102 Editor_state
.selection1
= {} -- no support for shift drag while we're resizing
103 Editor_state
.right
= App
.screen
.width
-Margin_right
104 Editor_state
.width
= Editor_state
.right
-Editor_state
.left
105 Text
.tweak_screen_top_and_cursor(Editor_state
, Editor_state
.left
, Editor_state
.right
)
108 function run
.file_drop(file
)
109 -- first make sure to save edits on any existing file
110 if Editor_state
.next_save
then
111 save_to_disk(Editor_state
)
113 -- clear the slate for the new file
114 App
.initialize_globals()
115 Editor_state
.filename
= file
:getFilename()
117 Editor_state
.lines
= load_from_file(file
)
119 Text
.redraw_all(Editor_state
)
120 Editor_state
.screen_top1
= {line
=1, pos
=1}
121 Editor_state
.cursor1
= {line
=1, pos
=1}
125 -- keep a few blank lines around: https://merveilles.town/@akkartik/110084833821965708
126 love
.window
.setTitle('lines.love - '..Editor_state
.filename
)
133 edit
.draw(Editor_state
)
136 function run
.update(dt
)
137 Cursor_time
= Cursor_time
+ dt
138 edit
.update(Editor_state
, dt
)
142 edit
.quit(Editor_state
)
145 function run
.settings()
146 if Settings
== nil then
149 if Current_app
== 'run' then
150 Settings
.x
, Settings
.y
, Settings
.displayindex
= App
.screen
.position()
152 local filename
= Editor_state
.filename
153 if is_relative_path(filename
) then
154 filename
= love
.filesystem
.getWorkingDirectory()..'/'..filename
-- '/' should work even on Windows
157 x
=Settings
.x
, y
=Settings
.y
, displayindex
=Settings
.displayindex
,
158 width
=App
.screen
.width
, height
=App
.screen
.height
,
159 font_height
=Editor_state
.font_height
,
161 screen_top
=Editor_state
.screen_top1
, cursor
=Editor_state
.cursor1
165 function run
.mouse_press(x
,y
, mouse_button
)
166 Cursor_time
= 0 -- ensure cursor is visible immediately after it moves
167 return edit
.mouse_press(Editor_state
, x
,y
, mouse_button
)
170 function run
.mouse_release(x
,y
, mouse_button
)
171 Cursor_time
= 0 -- ensure cursor is visible immediately after it moves
172 return edit
.mouse_release(Editor_state
, x
,y
, mouse_button
)
175 function run
.mouse_wheel_move(dx
,dy
)
176 Cursor_time
= 0 -- ensure cursor is visible immediately after it moves
177 return edit
.mouse_wheel_move(Editor_state
, dx
,dy
)
180 function run
.text_input(t
)
181 Cursor_time
= 0 -- ensure cursor is visible immediately after it moves
182 return edit
.text_input(Editor_state
, t
)
185 function run
.keychord_press(chord
, key
)
186 Cursor_time
= 0 -- ensure cursor is visible immediately after it moves
187 return edit
.keychord_press(Editor_state
, chord
, key
)
190 function run
.key_release(key
, scancode
)
191 Cursor_time
= 0 -- ensure cursor is visible immediately after it moves
192 return edit
.key_release(Editor_state
, key
, scancode
)
196 return love
.graphics
.getFont():getWidth(s
)