]> gitweb.factorcode.org Git - factor.git/blob - basis/ui/gadgets/editors/editors.factor
Revert "ui.gadgets.editors: remove extra spaces."
[factor.git] / basis / ui / gadgets / editors / editors.factor
1 ! Copyright (C) 2006, 2011 Slava Pestov
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays assocs calendar colors.constants
4 combinators combinators.short-circuit documents
5 documents.elements fry grouping kernel locals make math
6 math.functions math.order math.ranges math.rectangles
7 math.vectors models models.arrow namespaces opengl sequences
8 sorting splitting timers ui.baseline-alignment ui.clipboards
9 ui.commands ui.gadgets ui.gadgets.borders strings
10 ui.gadgets.line-support ui.gadgets.menus ui.gadgets.scrollers
11 ui.theme ui.gestures ui.pens.solid ui.render ui.text
12 unicode ;
13 EXCLUDE: fonts => selection ;
14 IN: ui.gadgets.editors
15
16 TUPLE: editor < line-gadget
17 caret-color
18 caret mark
19 focused? blink blink-timer ;
20
21 <PRIVATE
22
23 : <loc> ( -- loc ) { 0 0 } <model> ;
24
25 : init-editor-locs ( editor -- editor )
26     <loc> >>caret
27     <loc> >>mark ; inline
28
29 : editor-theme ( editor -- editor )
30     COLOR: red >>caret-color
31     monospace-font >>font ; inline
32
33 PRIVATE>
34
35 : new-editor ( class -- editor )
36     new-line-gadget
37         <document> >>model
38         init-editor-locs
39         editor-theme ; inline
40
41 : <editor> ( -- editor )
42     editor new-editor ;
43
44 <PRIVATE
45
46 : activate-editor-model ( editor model -- )
47     [ add-connection ]
48     [ nip activate-model ]
49     [ swap model>> add-loc ] 2tri ;
50
51 : deactivate-editor-model ( editor model -- )
52     [ remove-connection ]
53     [ nip deactivate-model ]
54     [ swap model>> remove-loc ] 2tri ;
55
56 : blink-caret ( editor -- )
57     [ not ] change-blink relayout-1 ;
58
59 SYMBOL: blink-interval
60
61 750 milliseconds blink-interval set-global
62
63 : stop-blinking ( editor -- )
64     blink-timer>> [ stop-timer ] when* ;
65
66 : start-blinking ( editor -- )
67     t >>blink
68     blink-timer>> [ restart-timer ] when* ;
69
70 : restart-blinking ( editor -- )
71     dup focused?>> [
72         [ start-blinking ]
73         [ relayout-1 ]
74         bi
75     ] [ drop ] if ;
76
77 PRIVATE>
78
79 M: editor graft*
80     [ dup caret>> activate-editor-model ]
81     [ dup mark>> activate-editor-model ]
82     [
83         [
84             '[ _ blink-caret ] blink-interval get dup <timer>
85         ] keep blink-timer<<
86     ] tri ;
87
88 M: editor ungraft*
89     [ [ stop-blinking ] [ f >>blink-timer drop ] bi ]
90     [ dup caret>> deactivate-editor-model ]
91     [ dup mark>> deactivate-editor-model ] tri ;
92
93 : editor-caret ( editor -- loc ) caret>> value>> ;
94
95 : editor-mark ( editor -- loc ) mark>> value>> ;
96
97 : set-caret ( loc editor -- )
98     [ model>> validate-loc ] [ caret>> ] bi set-model ;
99
100 : change-caret ( editor quot: ( loc document -- newloc ) -- )
101     [ [ [ editor-caret ] [ model>> ] bi ] dip call ] [ drop ] 2bi
102     set-caret ; inline
103
104 : mark>caret ( editor -- )
105     [ editor-caret ] [ mark>> ] bi set-model ;
106
107 : change-caret&mark ( editor quot: ( loc document -- newloc ) -- )
108     [ change-caret ] [ drop mark>caret ] 2bi ; inline
109
110 : editor-line ( n editor -- str ) control-value nth ;
111
112 :: point>loc ( point editor -- loc )
113     point second editor y>line {
114         { [ dup 0 < ] [ drop { 0 0 } ] }
115         { [ dup editor model>> last-line# > ] [ drop editor model>> doc-end ] }
116         [| n |
117             n
118             point first
119             editor font>>
120             n editor editor-line
121             x>offset 2array
122         ]
123     } cond ;
124
125 : clicked-loc ( editor -- loc )
126     [ hand-rel ] keep point>loc ;
127
128 : click-loc ( editor model -- )
129     [ clicked-loc ] dip set-model ;
130
131 : focus-editor ( editor -- )
132     [ start-blinking ] [ t >>focused? relayout-1 ] bi ;
133
134 : unfocus-editor ( editor -- )
135     [ stop-blinking ] [ f >>focused? relayout-1 ] bi ;
136
137 : loc>x ( loc editor -- x )
138     [ first2 swap ] dip [ editor-line ] [ font>> ] bi swap offset>x round ;
139
140 : loc>point ( loc editor -- loc )
141     [ loc>x ] [ [ first ] dip line>y ceiling ] 2bi 2array ;
142
143 : caret-loc ( editor -- loc )
144     [ editor-caret ] keep loc>point ;
145
146 : caret-dim ( editor -- dim )
147     [ 0 ] dip line-height 2array ;
148
149 : scroll>caret ( editor -- )
150     dup graft-state>> second [
151         [
152             [ caret-loc ] [ caret-dim { 2 1 } v+ ] bi <rect>
153         ] keep scroll>rect
154     ] [ drop ] if ;
155
156 <PRIVATE
157
158 : draw-caret? ( editor -- ? )
159     { [ focused?>> ] [ blink>> ] } 1&& ;
160
161 : draw-caret ( editor -- )
162     dup draw-caret? [
163         [ caret-color>> gl-color ]
164         [
165             [ caret-loc ] [ caret-dim ] bi
166             over v+ gl-line
167         ] bi
168     ] [ drop ] if ;
169
170 : selection-start/end ( editor -- start end )
171     [ editor-mark ] [ editor-caret ] bi sort-pair ;
172
173 SYMBOL: selected-lines
174
175 TUPLE: selected-line start end first? last? ;
176
177 : compute-selection ( editor -- assoc )
178     dup gadget-selection? [
179         [ selection-start/end [ [ first ] bi@ [a,b] ] [ ] 2bi ]
180         [ model>> ] bi
181         '[ [ _ _ ] [ _ start/end-on-line ] bi 2array ] H{ } map>assoc
182     ] [ drop f ] if ;
183
184 :: draw-selection ( line pair editor -- )
185     pair [ editor font>> line offset>x ] map :> pair
186     editor selection-color>> gl-color
187     pair first 0 2array
188     pair second pair first - round 1 max editor line-height 2array
189     gl-fill-rect ;
190
191 : draw-unselected-line ( line editor -- )
192     font>> swap draw-text ;
193
194 : draw-selected-line ( line pair editor -- )
195     over all-equal? [
196         [ nip draw-unselected-line ] [ draw-selection ] 3bi
197     ] [
198         [ draw-selection ]
199         [
200             [ [ first2 ] [ selection-color>> ] bi* <selection> ]
201             [ draw-unselected-line ] bi
202         ] 3bi
203     ] if ;
204
205 PRIVATE>
206
207 M: editor draw-line ( line index editor -- )
208     [ selected-lines get at ] dip over
209     [ draw-selected-line ] [ nip draw-unselected-line ] if ;
210
211 M: editor draw-gadget*
212     dup compute-selection selected-lines [
213         [ draw-lines ] [ draw-caret ] bi
214     ] with-variable ;
215
216 <PRIVATE
217
218 : row,col-dim ( font r c -- dim )
219     CHAR: x <string> swap
220     CHAR: \n <string>
221     append text-dim ;
222
223 : min-dim ( font editor -- dim )
224     [ min-rows>> [ 0 ] unless* ]
225     [ min-cols>> [ 0 ] unless* ] bi
226     row,col-dim ;
227     
228 : max-dim ( font editor -- dim )
229     ! hopefully no one goes over 5000
230     [ max-rows>> [ 5000 ] unless* ]
231     [ max-cols>> [ 5000 ] unless* ] bi
232     row,col-dim ;
233     
234 : txt-dim ( font editor -- dim )
235     control-value text-dim ;
236     
237 PRIVATE>
238
239 : editor-constrained-dim ( editor -- dim )
240     [ font>> ] keep
241     [ max-dim ]
242     [ txt-dim ]
243     [ min-dim ] 
244     2tri vmax vmin { 1 0 } v+ ;
245
246 M: editor pref-dim*
247     ! Add some space for the caret.
248     [ font>> ] [ control-value ] bi text-dim { 1 0 } v+ ;
249
250 M: editor baseline font>> font-metrics ascent>> ;
251
252 M: editor cap-height font>> font-metrics cap-height>> ;
253
254 <PRIVATE
255
256 : contents-changed ( model editor -- )
257     [ [ nip caret>> ] [ drop ] 2bi '[ _ validate-loc ] (change-model) ]
258     [ [ nip mark>> ] [ drop ] 2bi '[ _ validate-loc ] (change-model) ]
259     [ nip relayout ] 2tri ;
260
261 : caret/mark-changed ( editor -- )
262     [ restart-blinking ] keep scroll>caret ;
263
264 PRIVATE>
265
266 M: editor model-changed
267     {
268         { [ 2dup model>> eq? ] [ contents-changed ] }
269         { [ 2dup caret>> eq? ] [ nip caret/mark-changed ] }
270         { [ 2dup mark>> eq? ] [ nip caret/mark-changed ] }
271     } cond ;
272
273 M: editor gadget-selection?
274     selection-start/end = not ;
275
276 M: editor gadget-selection
277     [ selection-start/end ] [ model>> ] bi doc-range ;
278
279 : remove-selection ( editor -- )
280     [ selection-start/end ] [ model>> ] bi remove-doc-range ;
281
282 M: editor user-input*
283     [ selection-start/end ] [ model>> ] bi set-doc-range t ;
284
285 : editor-string ( editor -- string )
286     model>> doc-string ;
287
288 : set-editor-string ( string editor -- )
289     model>> set-doc-string ;
290
291 M: editor gadget-text* editor-string % ;
292
293 : extend-selection ( editor -- )
294     [ request-focus ]
295     [ restart-blinking ]
296     [ dup caret>> click-loc ] tri ;
297
298 : mouse-elt ( -- element )
299     hand-click# get {
300         { 1 one-char-elt }
301         { 2 one-word-elt }
302     } at one-line-elt or ;
303
304 : drag-direction? ( loc editor -- ? )
305     editor-mark before? ;
306
307 : drag-selection-caret ( loc editor element -- loc )
308     [
309         [ drag-direction? ] [ model>> ] 2bi
310     ] dip prev/next-elt ? ;
311
312 : drag-selection-mark ( loc editor element -- loc )
313     [
314         [ drag-direction? not ]
315         [ editor-mark ]
316         [ model>> ] tri
317     ] dip prev/next-elt ? ;
318
319 : drag-caret&mark ( editor -- caret mark )
320     [ clicked-loc ] [ mouse-elt ] bi
321     [ drag-selection-caret ]
322     [ drag-selection-mark ] 3bi ;
323
324 : drag-selection ( editor -- )
325     [ drag-caret&mark ]
326     [ mark>> set-model ]
327     [ caret>> set-model ] tri ;
328
329 : editor-cut ( editor clipboard -- )
330     [ gadget-copy ] [ drop remove-selection ] 2bi ;
331
332 : delete/backspace ( editor quot -- )
333     over gadget-selection? [
334         drop remove-selection
335     ] [
336         [ [ [ editor-caret ] [ model>> ] bi ] dip call ]
337         [ drop model>> ]
338         2bi remove-doc-range
339     ] if ; inline
340
341 : editor-delete ( editor elt -- )
342     '[ dupd _ next-elt ] delete/backspace ;
343
344 : editor-backspace ( editor elt -- )
345     '[ over [ _ prev-elt ] dip ] delete/backspace ;
346
347 : editor-select-prev ( editor elt -- )
348     '[ _ prev-elt ] change-caret ;
349
350 : editor-prev ( editor elt -- )
351     [ editor-select-prev ] [ drop mark>caret ] 2bi ;
352
353 : editor-select-next ( editor elt -- )
354     '[ _ next-elt ] change-caret ;
355
356 : editor-next ( editor elt -- )
357     dupd editor-select-next mark>caret ;
358
359 : editor-select ( from to editor -- )
360     [ mark>> set-model ] [ caret>> set-model ] bi-curry bi* ;
361
362 : select-elt ( editor elt -- )
363     [ [ [ editor-caret ] [ model>> ] bi ] dip prev/next-elt ] [ drop ] 2bi
364     editor-select ;
365
366 : start-of-document ( editor -- ) doc-elt editor-prev ;
367
368 : end-of-document ( editor -- ) doc-elt editor-next ;
369
370 : position-caret ( editor -- )
371     mouse-elt dup one-char-elt =
372     [ drop dup extend-selection dup mark>> click-loc ]
373     [ select-elt ] if ;
374
375 : delete-previous-character ( editor -- )
376     char-elt editor-backspace ;
377
378 : delete-next-character ( editor -- )
379     char-elt editor-delete ;
380
381 : delete-previous-word ( editor -- )
382     word-elt editor-backspace ;
383
384 : delete-next-word ( editor -- )
385     word-elt editor-delete ;
386
387 : delete-to-start-of-line ( editor -- )
388     one-line-elt editor-backspace ;
389
390 : delete-to-end-of-line ( editor -- )
391     one-line-elt editor-delete ;
392
393 : delete-to-start-of-document ( editor -- )
394     doc-elt editor-delete ;
395
396 : delete-to-end-of-document ( editor -- )
397     doc-elt editor-delete ;
398
399 : com-undo ( editor -- ) model>> undo ;
400
401 : com-redo ( editor -- ) model>> redo ;
402
403 editor "editing" f {
404     { undo-action com-undo }
405     { redo-action com-redo }
406     { T{ key-down f f "DELETE" } delete-next-character }
407     { T{ key-down f f "BACKSPACE" } delete-previous-character }
408     { T{ key-down f { S+ } "BACKSPACE" } delete-previous-character }
409     { T{ key-down f { C+ } "DELETE" } delete-next-word }
410     { T{ key-down f { C+ } "BACKSPACE" } delete-previous-word }
411     { T{ key-down f { A+ } "DELETE" } delete-to-end-of-line }
412     { T{ key-down f { A+ } "BACKSPACE" } delete-to-start-of-line }
413 } define-command-map
414
415 : com-paste ( editor -- ) clipboard get paste-clipboard ;
416
417 : paste-selection ( editor -- ) selection get paste-clipboard ;
418
419 : com-cut ( editor -- ) clipboard get editor-cut ;
420
421 editor "clipboard" f {
422     { cut-action com-cut }
423     { copy-action com-copy }
424     { paste-action com-paste }
425     { T{ button-up } com-copy-selection }
426     { T{ button-up f f 2 } paste-selection }
427 } define-command-map
428
429 : previous-character ( editor -- )
430     dup gadget-selection? [
431         dup selection-start/end drop
432         over set-caret mark>caret
433     ] [
434         char-elt editor-prev
435     ] if ;
436
437 : next-character ( editor -- )
438     dup gadget-selection? [
439         dup selection-start/end nip
440         over set-caret mark>caret
441     ] [
442         char-elt editor-next
443     ] if ;
444
445 : previous-word ( editor -- ) word-elt editor-prev ;
446
447 : next-word ( editor -- ) word-elt editor-next ;
448
449 : start-of-line ( editor -- ) one-line-elt editor-prev ;
450
451 : end-of-line ( editor -- ) one-line-elt editor-next ;
452
453 editor "caret-motion" f {
454     { T{ button-down } position-caret }
455     { T{ key-down f f "LEFT" } previous-character }
456     { T{ key-down f f "RIGHT" } next-character }
457     { T{ key-down f { C+ } "LEFT" } previous-word }
458     { T{ key-down f { C+ } "RIGHT" } next-word }
459     { T{ key-down f f "HOME" } start-of-line }
460     { T{ key-down f f "END" } end-of-line }
461     { T{ key-down f { C+ } "HOME" } start-of-document }
462     { T{ key-down f { C+ } "END" } end-of-document }
463 } define-command-map
464
465 : clear-editor ( editor -- )
466     model>> clear-doc ;
467
468 : select-all ( editor -- ) doc-elt select-elt ;
469
470 : select-line ( editor -- ) one-line-elt select-elt ;
471
472 : select-word ( editor -- ) one-word-elt select-elt ;
473
474 : selected-token ( editor -- string )
475     dup gadget-selection?
476     [ dup select-word ] unless
477     gadget-selection ;
478
479 : select-previous-character ( editor -- )
480     char-elt editor-select-prev ;
481
482 : select-next-character ( editor -- )
483     char-elt editor-select-next ;
484
485 : select-previous-word ( editor -- )
486     word-elt editor-select-prev ;
487
488 : select-next-word ( editor -- )
489     word-elt editor-select-next ;
490
491 : select-start-of-line ( editor -- )
492     one-line-elt editor-select-prev ;
493
494 : select-end-of-line ( editor -- )
495     one-line-elt editor-select-next ;
496
497 : select-start-of-document ( editor -- )
498     doc-elt editor-select-prev ;
499
500 : select-end-of-document ( editor -- )
501     doc-elt editor-select-next ;
502
503 editor "selection" f {
504     { T{ button-down f { S+ } 1 } extend-selection }
505     { T{ button-up f { S+ } 1 } com-copy-selection }
506     { T{ drag { # 1 } } drag-selection }
507     { gain-focus focus-editor }
508     { lose-focus unfocus-editor }
509     { delete-action remove-selection }
510     { select-all-action select-all }
511     { T{ key-down f { C+ } "l" } select-line }
512     { T{ key-down f { S+ } "LEFT" } select-previous-character }
513     { T{ key-down f { S+ } "RIGHT" } select-next-character }
514     { T{ key-down f { S+ C+ } "LEFT" } select-previous-word }
515     { T{ key-down f { S+ C+ } "RIGHT" } select-next-word }
516     { T{ key-down f { S+ } "HOME" } select-start-of-line }
517     { T{ key-down f { S+ } "END" } select-end-of-line }
518     { T{ key-down f { S+ C+ } "HOME" } select-start-of-document }
519     { T{ key-down f { S+ C+ } "END" } select-end-of-document }
520 } define-command-map
521
522 : editor-menu ( editor -- )
523     {
524         com-undo
525         com-redo
526         ----
527         com-cut
528         com-copy
529         com-paste
530     } show-commands-menu ;
531
532 editor "misc" f {
533     ! { T{ button-down f f 2 } paste-selection }
534     { T{ button-down f f 3 } editor-menu }
535 } define-command-map
536
537 ! Multi-line editors
538 TUPLE: multiline-editor < editor ;
539
540 : <multiline-editor> ( -- editor )
541     multiline-editor new-editor ;
542
543 : previous-line ( editor -- ) line-elt editor-prev ;
544
545 : next-line ( editor -- ) line-elt editor-next ;
546
547 <PRIVATE
548
549 : page-elt ( editor -- editor element ) dup visible-lines 1 - <page-elt> ;
550
551 PRIVATE>
552
553 : previous-page ( editor -- ) page-elt editor-prev ;
554
555 : next-page ( editor -- ) page-elt editor-next ;
556
557 : select-previous-line ( editor -- ) line-elt editor-select-prev ;
558
559 : select-next-line ( editor -- ) line-elt editor-select-next ;
560
561 : select-previous-page ( editor -- ) page-elt editor-select-prev ;
562
563 : select-next-page ( editor -- ) page-elt editor-select-next ;
564
565 : insert-newline ( editor -- )
566     "\n" swap user-input* drop ;
567
568 : change-selection ( editor quot -- )
569     '[ gadget-selection @ ] [ user-input* drop ] bi ; inline
570
571 <PRIVATE
572
573 : join-lines ( string -- string' )
574     "\n" split
575     [ rest-slice [ [ blank? ] trim-head-slice ] map! drop ]
576     [ but-last-slice [ [ blank? ] trim-tail-slice ] map! drop ]
577     [ " " join ]
578     tri ;
579
580 : last-line? ( document line -- ? )
581     [ last-line# ] dip = ;
582
583 : prev-line-and-this ( document line -- start end )
584     swap [ drop 1 - 0 2array ] [ line-end ] 2bi ;
585
586 : join-with-prev ( document line -- )
587     [ prev-line-and-this ] [ drop ] 2bi
588     [ join-lines ] change-doc-range ;
589
590 : this-line-and-next ( document line -- start end )
591     swap [ drop 0 2array ] [ [ 1 + ] dip line-end ] 2bi ;
592
593 : join-with-next ( document line -- )
594     [ this-line-and-next ] [ drop ] 2bi
595     [ join-lines ] change-doc-range ;
596
597 PRIVATE>
598
599 : com-join-lines ( editor -- )
600     dup gadget-selection?
601     [ [ join-lines ] change-selection ] [
602         [ model>> ] [ editor-caret first ] bi {
603             { [ over last-line# 0 = ] [ 2drop ] }
604             { [ 2dup last-line? ] [ join-with-prev ] }
605             [ join-with-next ]
606         } cond
607     ] if ;
608
609 multiline-editor "multiline" f {
610     { T{ key-down f f "UP" } previous-line }
611     { T{ key-down f f "DOWN" } next-line }
612     { T{ key-down f { S+ } "UP" } select-previous-line }
613     { T{ key-down f { S+ } "DOWN" } select-next-line }
614     { T{ key-down f f "PAGE_UP" } previous-page }
615     { T{ key-down f f "PAGE_DOWN" } next-page }
616     { T{ key-down f { S+ } "PAGE_UP" } select-previous-page }
617     { T{ key-down f { S+ } "PAGE_DOWN" } select-next-page }
618     { T{ key-down f f "RET" } insert-newline }
619     { T{ key-down f { S+ } "RET" } insert-newline }
620     { T{ key-down f f "ENTER" } insert-newline }
621     { T{ key-down f { C+ } "j" } com-join-lines }
622 } define-command-map
623
624 TUPLE: source-editor < multiline-editor ;
625
626 : <source-editor> ( -- editor )
627     source-editor new-editor ;
628
629 ! A useful model
630 : <element-model> ( editor element -- model )
631     [ [ caret>> ] [ model>> ] bi ] dip
632     '[ _ _ elt-string ] <arrow> ;
633
634 ! Fields wrap an editor
635 TUPLE: field < border editor min-cols max-cols ;
636
637 <PRIVATE
638
639 : field-theme ( gadget -- gadget )
640     { 2 2 } >>size
641     { 1 0 } >>fill
642     field-border-color <solid> >>boundary ; inline
643
644 : <field-border> ( gadget -- border )
645     border new-border field-theme ;
646
647 PRIVATE>
648
649 : new-field ( class -- gadget )
650     [ <editor> ] dip new-border
651         dup gadget-child >>editor
652         field-theme ; inline
653
654 ! For line-gadget-width
655 M: field font>> editor>> font>> ;
656
657 M: field pref-dim*
658     [ ]
659     [ editor>> pref-dim ]
660     [ [ line-gadget-width ] [ drop second ] 2bi 2array ]
661     tri border-pref-dim ;
662
663 TUPLE: model-field < field field-model ;
664
665 : <model-field> ( model -- gadget )
666     model-field new-field
667         swap >>field-model ;
668
669 M: model-field graft*
670     [ [ field-model>> value>> ] [ editor>> ] bi set-editor-string ]
671     [ dup editor>> model>> add-connection ]
672     bi ;
673
674 M: model-field ungraft*
675     dup editor>> model>> remove-connection ;
676
677 M: model-field model-changed
678     nip [ editor>> editor-string ] [ field-model>> ] bi set-model ;
679
680 TUPLE: action-editor < editor default-text ;
681
682 : <action-editor> ( -- editor )
683     action-editor new-editor ;
684
685 <PRIVATE
686
687 : draw-default-text? ( editor -- ? )
688     { [ default-text>> ] [ model>> doc-string empty? ] } 1&& ;
689
690 : draw-default-text ( editor -- )
691     [ font>> clone line-color >>foreground ]
692     [ default-text>> ] bi draw-text ;
693
694 PRIVATE>
695
696 M: action-editor draw-gadget*
697     dup draw-default-text? [
698         [ draw-default-text ] [ draw-caret ] bi
699     ] [
700         call-next-method
701     ] if ;
702
703 TUPLE: action-field < field quot ;
704
705 : <action-field> ( quot: ( string -- ) -- gadget )
706     action-field [ <action-editor> ] dip new-border
707         dup gadget-child >>editor
708         field-theme
709         swap >>quot ;
710
711 M: action-field default-text>> editor>> default-text>> ;
712
713 M: action-field default-text<< editor>> default-text<< ;
714
715 : invoke-action-field ( field -- )
716     [ editor>> editor-string ]
717     [ editor>> clear-editor ]
718     [ quot>> ]
719     tri call( string -- ) ;
720
721 action-field H{
722     { T{ key-down f f "RET" } [ invoke-action-field ] }
723 } set-gestures