1 USING: documents help.markup help.syntax ui.gadgets
2 ui.gadgets.scrollers models strings ui.commands sequences
3 ui.text colors fonts help.tips ;
7 { $class-description "An editor is a control for editing a multi-line passage of text stored in a " { $link document } " model. Editors are crated by calling " { $link <editor> } "."
9 "Editors have the following slots:"
11 { { $snippet "font" } " - a " { $link font } "." }
12 { { $snippet "color" } " - a " { $link color } "." }
13 { { $snippet "caret-color" } " - a " { $link color } "." }
14 { { $snippet "selection-color" } " - a " { $link color } "." }
15 { { $snippet "caret" } " - a " { $link model } " storing a line/column pair." }
16 { { $snippet "mark" } " - a " { $link model } " storing a line/column pair. If there is no selection, the mark is equal to the caret, otherwise the mark is located at the opposite end of the selection from the caret." }
17 { { $snippet "focused?" } " - a boolean." }
21 { $values { "editor" "a new " { $link editor } } }
22 { $description "Creates a new " { $link editor } " with an empty document." } ;
24 { editor-caret editor-mark } related-words
27 { $values { "editor" editor } { "loc" "a pair of integers" } }
28 { $description "Outputs the current caret location as a line/column number pair." } ;
31 { $values { "editor" editor } { "loc" "a pair of integers" } }
32 { $description "Outputs the current mark location as a line/column number pair." } ;
35 { $values { "editor" editor } { "quot" { $quotation ( loc document -- newloc ) } } }
36 { $description "Applies a quotation to the current caret location and moves the caret to the location output by the quotation." } ;
38 { change-caret change-caret&mark mark>caret } related-words
41 { $values { "editor" editor } }
42 { $description "Moves the mark to the caret location, effectively deselecting any selected text." } ;
44 HELP: change-caret&mark
45 { $values { "editor" editor } { "quot" { $quotation ( loc document -- newloc ) } } }
46 { $description "Applies a quotation to the current caret location and moves the caret and the mark to the location output by the quotation." } ;
49 { $values { "point" "a pair of integers" } { "editor" editor } { "loc" "a pair of integers" } }
50 { $description "Converts a point to a line/column number pair." } ;
53 { $values { "editor" editor } }
54 { $description "Ensures that the caret becomes visible in a " { $link scroller } " containing the editor. Does nothing if no parent of " { $snippet "gadget" } " is a " { $link scroller } "." } ;
56 HELP: remove-selection
57 { $values { "editor" editor } }
58 { $description "Removes currently selected text from the editor's " { $link document } "." } ;
61 { $values { "model" model } { "gadget" editor } }
62 { $description "Creates an editor gadget which targets the specified model. The model must contain a string, or another item with a defined " { $link length } ", as this will be checked during layout." } ;
65 { $values { "quot" "a quotation ( string -- )" } { "gadget" editor } }
66 { $description "Creates an editor gadget with a blank model. Whenever a value is entered into the editor and Return pressed, the value is pushed on the stack as a string and the specified quotation is called. Note that the quotation cannot update the value in the field. " } ;
70 { $values { "editor" editor } { "string" string } }
71 { $description "Outputs the contents of the editor's " { $link document } " as a string. Lines are separated by " { $snippet "\\n" } "." } ;
75 HELP: set-editor-string
76 { $values { "string" string } { "editor" editor } }
77 { $description "Sets the contents of the editor's " { $link document } " to a string, which may use either " { $snippet "\\n" } ", " { $snippet "\\r\\n" } " or " { $snippet "\\r" } " line separators." } ;
79 ARTICLE: "gadgets-editors-selection" "The caret and mark"
80 "If there is no selection, the caret and the mark are at the same location; otherwise the mark delimits the end-point of the selection opposite the caret."
88 "Getting the selected text:"
93 "Removing selected text:"
94 { $subsections remove-selection }
95 "Scrolling to the caret location:"
96 { $subsections scroll>caret }
97 "Use " { $link user-input* } " to change selected text." ;
99 ARTICLE: "gadgets-editors-contents" "Getting and setting editor contents"
106 ARTICLE: "gadgets-editors-commands" "Editor gadget commands"
107 { $command-map editor "editing" }
108 { $command-map editor "caret-motion" }
109 { $command-map editor "selection" }
110 { $command-map editor "clipboard" }
111 { $command-map multiline-editor "multiline" } ;
113 ARTICLE: "ui.gadgets.editors" "Editor gadgets"
114 "The " { $vocab-link "ui.gadgets.editors" } " vocabulary implements editor gadgets. An editor edits a passage of text. Editors display a " { $link document } ". Editors are built from and inherit all features of " { $link "ui.gadgets.line-support" } "."
115 { $subsections "gadgets-editors-commands" }
120 "gadgets-editors-contents"
121 "gadgets-editors-selection"
124 { $subsections <multiline-editor> }
130 "Editors edit " { $emphasis "documents" } ":"
131 { $subsections "documents" } ;
133 TIP: "Editor gadgets support undo and redo; press " { $command editor "editing" com-undo } " and " { $command editor "editing" com-redo } "." ;
135 TIP: "Learn the keyboard shortcuts used in " { $link "ui.gadgets.editors" } "." ;
137 ABOUT: "ui.gadgets.editors"