source_edit.lua 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. -- some constants people might like to tweak
  2. Text_color = {r=0, g=0, b=0}
  3. Cursor_color = {r=1, g=0, b=0}
  4. Hyperlink_decoration_color = {r=0.4, g=0.4, b=1}
  5. Stroke_color = {r=0, g=0, b=0}
  6. Current_stroke_color = {r=0.7, g=0.7, b=0.7} -- in process of being drawn
  7. Current_name_background_color = {r=1, g=0, b=0, a=0.1} -- name currently being edited
  8. Focus_stroke_color = {r=1, g=0, b=0} -- what mouse is hovering over
  9. Highlight_color = {r=0.7, g=0.7, b=0.9} -- selected text
  10. Line_number_color = {r=0.6, g=0.6, b=0.6}
  11. Icon_color = {r=0.7, g=0.7, b=0.7} -- color of current mode icon in drawings
  12. Help_color = {r=0, g=0.5, b=0}
  13. Help_background_color = {r=0, g=0.5, b=0, a=0.1}
  14. Margin_top = 15
  15. Margin_left = 25
  16. Margin_right = 25
  17. Drawing_padding_top = 10
  18. Drawing_padding_bottom = 10
  19. Drawing_padding_height = Drawing_padding_top + Drawing_padding_bottom
  20. Same_point_distance = 4 -- pixel distance at which two points are considered the same
  21. edit = {}
  22. -- run in both tests and a real run
  23. function edit.initialize_state(top, left, right, font, font_height, line_height) -- currently always draws to bottom of screen
  24. local result = {
  25. -- a line is either text or a drawing
  26. -- a text is a table with:
  27. -- mode = 'text',
  28. -- string data,
  29. -- a drawing is a table with:
  30. -- mode = 'drawing'
  31. -- a (h)eight,
  32. -- an array of points, and
  33. -- an array of shapes
  34. -- a shape is a table containing:
  35. -- a mode
  36. -- an array points for mode 'freehand' (raw x,y coords; freehand drawings don't pollute the points array of a drawing)
  37. -- an array vertices for mode 'polygon', 'rectangle', 'square'
  38. -- p1, p2 for mode 'line'
  39. -- center, radius for mode 'circle'
  40. -- center, radius, start_angle, end_angle for mode 'arc'
  41. -- Unless otherwise specified, coord fields are normalized; a drawing is always 256 units wide
  42. -- The field names are carefully chosen so that switching modes in midstream
  43. -- remembers previously entered points where that makes sense.
  44. lines = {{mode='text', data=''}}, -- array of lines
  45. -- Lines can be too long to fit on screen, in which case they _wrap_ into
  46. -- multiple _screen lines_.
  47. -- rendering wrapped text lines needs some additional short-lived data per line:
  48. -- startpos, the index of data the line starts rendering from, can only be >1 for topmost line on screen
  49. -- screen_line_starting_pos: optional array of codepoint indices if it wraps over more than one screen line
  50. line_cache = {},
  51. -- Given wrapping, any potential location for the text cursor can be described in two ways:
  52. -- * schema 1: As a combination of line index and position within a line (in utf8 codepoint units)
  53. -- * schema 2: As a combination of line index, screen line index within the line, and a position within the screen line.
  54. --
  55. -- Most of the time we'll only persist positions in schema 1, translating to
  56. -- schema 2 when that's convenient.
  57. --
  58. -- Make sure these coordinates are never aliased, so that changing one causes
  59. -- action at a distance.
  60. --
  61. -- On lines that are drawings, pos will be nil.
  62. screen_top1 = {line=1, pos=1}, -- position of start of screen line at top of screen
  63. cursor1 = {line=1, pos=1}, -- position of cursor; must be on a text line
  64. selection1 = {},
  65. -- some extra state to compute selection between mouse press and release
  66. old_cursor1 = nil,
  67. old_selection1 = nil,
  68. mousepress_shift = nil,
  69. -- cursor coordinates in pixels
  70. cursor_x = 0,
  71. cursor_y = 0,
  72. current_drawing_mode = 'line',
  73. previous_drawing_mode = nil, -- extra state for some ephemeral modes like moving/deleting/naming points
  74. font = font,
  75. font_height = font_height,
  76. line_height = line_height,
  77. top = top,
  78. left = math.floor(left), -- left margin for text; line numbers go to the left of this
  79. right = math.floor(right),
  80. width = right-left,
  81. filename = 'run.lua',
  82. next_save = nil,
  83. -- undo
  84. history = {},
  85. next_history = 1,
  86. -- search
  87. search_term = nil,
  88. search_backup = nil, -- stuff to restore when cancelling search
  89. }
  90. return result
  91. end -- edit.initialize_state
  92. function edit.check_locs(State)
  93. -- if State is inconsistent (i.e. file changed by some other program),
  94. -- throw away all cursor state entirely
  95. if edit.invalid1(State, State.screen_top1)
  96. or edit.invalid_cursor1(State)
  97. or not edit.cursor_on_text(State)
  98. or not Text.le1(State.screen_top1, State.cursor1) then
  99. State.screen_top1 = {line=1, pos=1}
  100. State.cursor1 = {line=1, pos=1}
  101. edit.put_cursor_on_next_text_line(State)
  102. end
  103. end
  104. function edit.invalid1(State, loc1)
  105. if loc1.line > #State.lines then return true end
  106. local l = State.lines[loc1.line]
  107. if l.mode ~= 'text' then return false end -- pos is irrelevant to validity for a drawing line
  108. return loc1.pos > #State.lines[loc1.line].data
  109. end
  110. -- cursor loc in particular differs from other locs in one way:
  111. -- pos might occur just after end of line
  112. function edit.invalid_cursor1(State)
  113. local cursor1 = State.cursor1
  114. if cursor1.line > #State.lines then return true end
  115. local l = State.lines[cursor1.line]
  116. if l.mode ~= 'text' then return false end -- pos is irrelevant to validity for a drawing line
  117. return cursor1.pos > #State.lines[cursor1.line].data + 1
  118. end
  119. function edit.cursor_on_text(State)
  120. return State.cursor1.line <= #State.lines
  121. and State.lines[State.cursor1.line].mode == 'text'
  122. end
  123. function edit.put_cursor_on_next_text_line(State)
  124. local line = State.cursor1.line
  125. while line < #State.lines do
  126. line = line+1
  127. if State.lines[line].mode == 'text' then
  128. State.cursor1.line = line
  129. State.cursor1.pos = 1
  130. break
  131. end
  132. end
  133. end
  134. function edit.draw(State, hide_cursor, show_line_numbers)
  135. State.button_handlers = {}
  136. love.graphics.setFont(State.font)
  137. App.color(Text_color)
  138. assert(#State.lines == #State.line_cache, ('line_cache is out of date; %d elements when it should be %d'):format(#State.line_cache, #State.lines))
  139. assert(Text.le1(State.screen_top1, State.cursor1), ('screen_top (line=%d,pos=%d) is below cursor (line=%d,pos=%d)'):format(State.screen_top1.line, State.screen_top1.pos, State.cursor1.line, State.cursor1.pos))
  140. State.cursor_x = nil
  141. State.cursor_y = nil
  142. local y = State.top
  143. --? print('== draw')
  144. for line_index = State.screen_top1.line,#State.lines do
  145. local line = State.lines[line_index]
  146. --? print('draw:', y, line_index, line)
  147. if y + State.line_height > App.screen.height then break end
  148. if line.mode == 'text' then
  149. --? print('text.draw', y, line_index)
  150. local startpos = 1
  151. if line_index == State.screen_top1.line then
  152. startpos = State.screen_top1.pos
  153. end
  154. if line.data == '' then
  155. -- button to insert new drawing
  156. local buttonx = State.left-Margin_left+4
  157. if show_line_numbers then
  158. buttonx = 4 -- HACK: position draw buttons at a fixed x on screen
  159. end
  160. button(State, 'draw', {x=buttonx, y=y+4, w=12,h=12, bg={r=1,g=1,b=0},
  161. icon = icon.insert_drawing,
  162. onpress1 = function()
  163. Drawing.before = snapshot(State, line_index-1, line_index)
  164. table.insert(State.lines, line_index, {mode='drawing', y=y, h=256/2, points={}, shapes={}, pending={}})
  165. table.insert(State.line_cache, line_index, {})
  166. if State.cursor1.line >= line_index then
  167. State.cursor1.line = State.cursor1.line+1
  168. end
  169. record_undo_event(State, {before=Drawing.before, after=snapshot(State, line_index-1, line_index+1)})
  170. Drawing.before = nil
  171. schedule_save(State)
  172. end,
  173. })
  174. end
  175. y = Text.draw(State, line_index, y, startpos, hide_cursor, show_line_numbers)
  176. --? print('=> y', y)
  177. elseif line.mode == 'drawing' then
  178. y = y+Drawing_padding_top
  179. Drawing.draw(State, line_index, y)
  180. y = y + Drawing.pixels(line.h, State.width) + Drawing_padding_bottom
  181. else
  182. assert(false, ('unknown line mode %s'):format(line.mode))
  183. end
  184. end
  185. if State.search_term then
  186. Text.draw_search_bar(State)
  187. end
  188. end
  189. function edit.update(State, dt)
  190. Drawing.update(State, dt)
  191. if State.next_save and State.next_save < Current_time then
  192. save_to_disk(State)
  193. State.next_save = nil
  194. end
  195. end
  196. function schedule_save(State)
  197. if State.next_save == nil then
  198. State.next_save = Current_time + 3 -- short enough that you're likely to still remember what you did
  199. end
  200. end
  201. function edit.quit(State)
  202. -- make sure to save before quitting
  203. if State.next_save then
  204. save_to_disk(State)
  205. -- give some time for the OS to flush everything to disk
  206. love.timer.sleep(0.1)
  207. end
  208. end
  209. function edit.mouse_press(State, x,y, mouse_button)
  210. if State.search_term then return end
  211. State.mouse_down = mouse_button
  212. --? print_and_log(('edit.mouse_press: cursor at %d,%d'):format(State.cursor1.line, State.cursor1.pos))
  213. if mouse_press_consumed_by_any_button(State, x,y, mouse_button) then
  214. -- press on a button and it returned 'true' to short-circuit
  215. return
  216. end
  217. if y < State.top then
  218. State.old_cursor1 = State.cursor1
  219. State.old_selection1 = State.selection1
  220. State.mousepress_shift = App.shift_down()
  221. State.selection1 = {
  222. line=State.screen_top1.line,
  223. pos=State.screen_top1.pos,
  224. }
  225. return
  226. end
  227. for line_index,line in ipairs(State.lines) do
  228. if line.mode == 'text' then
  229. if Text.in_line(State, line_index, x,y) then
  230. -- delicate dance between cursor, selection and old cursor/selection
  231. -- scenarios:
  232. -- regular press+release: sets cursor, clears selection
  233. -- shift press+release:
  234. -- sets selection to old cursor if not set otherwise leaves it untouched
  235. -- sets cursor
  236. -- press and hold to start a selection: sets selection on press, cursor on release
  237. -- press and hold, then press shift: ignore shift
  238. -- i.e. mouse_release should never look at shift state
  239. --? print_and_log(('edit.mouse_press: in line %d'):format(line_index))
  240. State.old_cursor1 = State.cursor1
  241. State.old_selection1 = State.selection1
  242. State.mousepress_shift = App.shift_down()
  243. State.selection1 = {
  244. line=line_index,
  245. pos=Text.to_pos_on_line(State, line_index, x, y),
  246. }
  247. return
  248. end
  249. elseif line.mode == 'drawing' then
  250. if Drawing.in_drawing(State, line_index, x, y, State.left,State.right) then
  251. State.lines.current_drawing_index = line_index
  252. State.lines.current_drawing = line
  253. Drawing.before = snapshot(State, line_index)
  254. Drawing.mouse_press(State, line_index, x,y, mouse_button)
  255. return
  256. end
  257. end
  258. end
  259. -- still here? mouse press is below all screen lines
  260. State.old_cursor1 = State.cursor1
  261. State.old_selection1 = State.selection1
  262. State.mousepress_shift = App.shift_down()
  263. State.selection1 = Text.final_text_loc_on_screen(State)
  264. end
  265. function edit.mouse_release(State, x,y, mouse_button)
  266. if State.search_term then return end
  267. --? print_and_log(('edit.mouse_release: cursor at %d,%d'):format(State.cursor1.line, State.cursor1.pos))
  268. State.mouse_down = nil
  269. if State.lines.current_drawing then
  270. Drawing.mouse_release(State, x,y, mouse_button)
  271. if Drawing.before then
  272. record_undo_event(State, {before=Drawing.before, after=snapshot(State, State.lines.current_drawing_index)})
  273. Drawing.before = nil
  274. end
  275. schedule_save(State)
  276. else
  277. --? print_and_log('edit.mouse_release: no current drawing')
  278. if y < State.top then
  279. State.cursor1 = deepcopy(State.screen_top1)
  280. edit.clean_up_mouse_press(State)
  281. return
  282. end
  283. for line_index,line in ipairs(State.lines) do
  284. if line.mode == 'text' then
  285. if Text.in_line(State, line_index, x,y) then
  286. --? print_and_log(('edit.mouse_release: in line %d'):format(line_index))
  287. State.cursor1 = {
  288. line=line_index,
  289. pos=Text.to_pos_on_line(State, line_index, x, y),
  290. }
  291. --? print_and_log(('edit.mouse_release: cursor now %d,%d'):format(State.cursor1.line, State.cursor1.pos))
  292. edit.clean_up_mouse_press(State)
  293. return
  294. end
  295. end
  296. end
  297. -- still here? mouse release is below all screen lines
  298. State.cursor1 = Text.final_text_loc_on_screen(State)
  299. edit.clean_up_mouse_press(State)
  300. --? print_and_log(('edit.mouse_release: finally selection %s,%s cursor %d,%d'):format(tostring(State.selection1.line), tostring(State.selection1.pos), State.cursor1.line, State.cursor1.pos))
  301. end
  302. end
  303. function edit.clean_up_mouse_press(State)
  304. if State.mousepress_shift then
  305. if State.old_selection1.line == nil then
  306. State.selection1 = State.old_cursor1
  307. else
  308. State.selection1 = State.old_selection1
  309. end
  310. end
  311. State.old_cursor1, State.old_selection1, State.mousepress_shift = nil
  312. if eq(State.cursor1, State.selection1) then
  313. State.selection1 = {}
  314. end
  315. end
  316. function edit.mouse_wheel_move(State, dx,dy)
  317. if dy > 0 then
  318. State.cursor1 = deepcopy(State.screen_top1)
  319. edit.put_cursor_on_next_text_line(State)
  320. for i=1,math.floor(dy) do
  321. Text.up(State)
  322. end
  323. elseif dy < 0 then
  324. State.cursor1 = Text.screen_bottom1(State)
  325. edit.put_cursor_on_next_text_line(State)
  326. for i=1,math.floor(-dy) do
  327. Text.down(State)
  328. end
  329. end
  330. end
  331. function edit.text_input(State, t)
  332. --? print('text input', t)
  333. if State.search_term then
  334. State.search_term = State.search_term..t
  335. Text.search_next(State)
  336. elseif State.lines.current_drawing and State.current_drawing_mode == 'name' then
  337. local before = snapshot(State, State.lines.current_drawing_index)
  338. local drawing = State.lines.current_drawing
  339. local p = drawing.points[drawing.pending.target_point]
  340. p.name = p.name..t
  341. record_undo_event(State, {before=before, after=snapshot(State, State.lines.current_drawing_index)})
  342. else
  343. local drawing_index, drawing = Drawing.current_drawing(State)
  344. if drawing_index == nil then
  345. Text.text_input(State, t)
  346. end
  347. end
  348. schedule_save(State)
  349. end
  350. function edit.keychord_press(State, chord, key)
  351. if State.selection1.line and
  352. not State.lines.current_drawing and
  353. -- printable character created using shift key => delete selection
  354. -- (we're not creating any ctrl-shift- or alt-shift- combinations using regular/printable keys)
  355. (not App.shift_down() or utf8.len(key) == 1) and
  356. 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
  357. Text.delete_selection_and_record_undo_event(State)
  358. end
  359. if State.search_term then
  360. if chord == 'escape' then
  361. State.search_term = nil
  362. State.cursor1 = State.search_backup.cursor
  363. State.screen_top1 = State.search_backup.screen_top
  364. State.search_backup = nil
  365. Text.redraw_all(State) -- if we're scrolling, reclaim all line caches to avoid memory leaks
  366. elseif chord == 'return' then
  367. State.search_term = nil
  368. State.search_backup = nil
  369. elseif chord == 'backspace' then
  370. local len = utf8.len(State.search_term)
  371. local byte_offset = Text.offset(State.search_term, len)
  372. State.search_term = string.sub(State.search_term, 1, byte_offset-1)
  373. State.cursor = deepcopy(State.search_backup.cursor)
  374. State.screen_top = deepcopy(State.search_backup.screen_top)
  375. Text.search_next(State)
  376. elseif chord == 'down' then
  377. if #State.search_term > 0 then
  378. Text.right(State)
  379. Text.search_next(State)
  380. end
  381. elseif chord == 'up' then
  382. Text.search_previous(State)
  383. end
  384. return
  385. elseif chord == 'C-f' then
  386. State.search_term = ''
  387. State.search_backup = {
  388. cursor={line=State.cursor1.line, pos=State.cursor1.pos},
  389. screen_top={line=State.screen_top1.line, pos=State.screen_top1.pos},
  390. }
  391. -- zoom
  392. elseif chord == 'C-=' then
  393. edit.update_font_settings(State, State.font_height+2)
  394. Text.redraw_all(State)
  395. elseif chord == 'C--' then
  396. if State.font_height > 2 then
  397. edit.update_font_settings(State, State.font_height-2)
  398. Text.redraw_all(State)
  399. end
  400. elseif chord == 'C-0' then
  401. edit.update_font_settings(State, 20)
  402. Text.redraw_all(State)
  403. -- undo
  404. elseif chord == 'C-z' then
  405. local event = undo_event(State)
  406. if event then
  407. local src = event.before
  408. State.screen_top1 = deepcopy(src.screen_top)
  409. State.cursor1 = deepcopy(src.cursor)
  410. State.selection1 = deepcopy(src.selection)
  411. patch(State.lines, event.after, event.before)
  412. -- invalidate various cached bits of lines
  413. State.lines.current_drawing = nil
  414. Text.redraw_all(State) -- if we're scrolling, reclaim all line caches to avoid memory leaks
  415. schedule_save(State)
  416. end
  417. elseif chord == 'C-y' then
  418. local event = redo_event(State)
  419. if event then
  420. local src = event.after
  421. State.screen_top1 = deepcopy(src.screen_top)
  422. State.cursor1 = deepcopy(src.cursor)
  423. State.selection1 = deepcopy(src.selection)
  424. patch(State.lines, event.before, event.after)
  425. -- invalidate various cached bits of lines
  426. State.lines.current_drawing = nil
  427. Text.redraw_all(State) -- if we're scrolling, reclaim all line caches to avoid memory leaks
  428. schedule_save(State)
  429. end
  430. -- clipboard
  431. elseif chord == 'C-a' then
  432. State.selection1 = {line=1, pos=1}
  433. State.cursor1 = {line=#State.lines, pos=utf8.len(State.lines[#State.lines].data)+1}
  434. elseif chord == 'C-c' then
  435. local s = Text.selection(State)
  436. if s then
  437. App.set_clipboard(s)
  438. end
  439. elseif chord == 'C-x' then
  440. local s = Text.cut_selection_and_record_undo_event(State)
  441. if s then
  442. App.set_clipboard(s)
  443. end
  444. schedule_save(State)
  445. elseif chord == 'C-v' then
  446. -- We don't have a good sense of when to scroll, so we'll be conservative
  447. -- and sometimes scroll when we didn't quite need to.
  448. local before_line = State.cursor1.line
  449. local before = snapshot(State, before_line)
  450. local clipboard_data = App.get_clipboard()
  451. for _,code in utf8.codes(clipboard_data) do
  452. local c = utf8.char(code)
  453. if c == '\n' then
  454. Text.insert_return(State)
  455. else
  456. Text.insert_at_cursor(State, c)
  457. end
  458. end
  459. if Text.cursor_out_of_screen(State) then
  460. Text.snap_cursor_to_bottom_of_screen(State, State.left, State.right)
  461. end
  462. record_undo_event(State, {before=before, after=snapshot(State, before_line, State.cursor1.line)})
  463. schedule_save(State)
  464. -- dispatch to drawing or text
  465. elseif App.mouse_down(1) or chord:sub(1,2) == 'C-' then
  466. local drawing_index, drawing = Drawing.current_drawing(State)
  467. if drawing_index then
  468. local before = snapshot(State, drawing_index)
  469. Drawing.keychord_press(State, chord)
  470. record_undo_event(State, {before=before, after=snapshot(State, drawing_index)})
  471. schedule_save(State)
  472. end
  473. elseif chord == 'escape' and not App.mouse_down(1) then
  474. for _,line in ipairs(State.lines) do
  475. if line.mode == 'drawing' then
  476. line.show_help = false
  477. end
  478. end
  479. elseif State.lines.current_drawing and State.current_drawing_mode == 'name' then
  480. if chord == 'return' then
  481. State.current_drawing_mode = State.previous_drawing_mode
  482. State.previous_drawing_mode = nil
  483. else
  484. local before = snapshot(State, State.lines.current_drawing_index)
  485. local drawing = State.lines.current_drawing
  486. local p = drawing.points[drawing.pending.target_point]
  487. if chord == 'escape' then
  488. p.name = nil
  489. record_undo_event(State, {before=before, after=snapshot(State, State.lines.current_drawing_index)})
  490. elseif chord == 'backspace' then
  491. local len = utf8.len(p.name)
  492. if len > 0 then
  493. local byte_offset = Text.offset(p.name, len-1)
  494. if len == 1 then byte_offset = 0 end
  495. p.name = string.sub(p.name, 1, byte_offset)
  496. record_undo_event(State, {before=before, after=snapshot(State, State.lines.current_drawing_index)})
  497. end
  498. end
  499. end
  500. schedule_save(State)
  501. else
  502. Text.keychord_press(State, chord)
  503. end
  504. end
  505. function edit.key_release(State, key, scancode)
  506. end
  507. function edit.update_font_settings(State, font_height)
  508. State.font_height = font_height
  509. State.font = love.graphics.newFont(State.font_height)
  510. State.line_height = math.floor(font_height*1.3)
  511. end
  512. --== some methods for tests
  513. -- Insulate tests from some key globals so I don't have to change the vast
  514. -- majority of tests when they're modified for the real app.
  515. Test_margin_left = 25
  516. Test_margin_right = 0
  517. function edit.initialize_test_state()
  518. -- if you change these values, tests will start failing
  519. return edit.initialize_state(
  520. 15, -- top margin
  521. Test_margin_left,
  522. App.screen.width - Test_margin_right,
  523. love.graphics.getFont(),
  524. 14,
  525. 15) -- line height
  526. end
  527. -- all text_input events are also keypresses
  528. -- TODO: handle chords of multiple keys
  529. function edit.run_after_text_input(State, t)
  530. edit.keychord_press(State, t)
  531. edit.text_input(State, t)
  532. edit.key_release(State, t)
  533. App.screen.contents = {}
  534. edit.update(State, 0)
  535. edit.draw(State)
  536. end
  537. -- not all keys are text_input
  538. function edit.run_after_keychord(State, chord, key)
  539. edit.keychord_press(State, chord, key)
  540. edit.key_release(State, key)
  541. App.screen.contents = {}
  542. edit.update(State, 0)
  543. edit.draw(State)
  544. end
  545. function edit.run_after_mouse_click(State, x,y, mouse_button)
  546. App.fake_mouse_press(x,y, mouse_button)
  547. edit.mouse_press(State, x,y, mouse_button)
  548. edit.draw(State)
  549. App.fake_mouse_release(x,y, mouse_button)
  550. edit.mouse_release(State, x,y, mouse_button)
  551. App.screen.contents = {}
  552. edit.update(State, 0)
  553. edit.draw(State)
  554. end
  555. function edit.run_after_mouse_press(State, x,y, mouse_button)
  556. App.fake_mouse_press(x,y, mouse_button)
  557. edit.mouse_press(State, x,y, mouse_button)
  558. App.screen.contents = {}
  559. edit.update(State, 0)
  560. edit.draw(State)
  561. end
  562. function edit.run_after_mouse_release(State, x,y, mouse_button)
  563. App.fake_mouse_release(x,y, mouse_button)
  564. edit.mouse_release(State, x,y, mouse_button)
  565. App.screen.contents = {}
  566. edit.update(State, 0)
  567. edit.draw(State)
  568. end