ยค editorF, editorF', et al

Text editors

Types

editorF :: F EditCmd EditEvt
editorF' :: Customiser EditorF -> F EditCmd EditEvt
data EditorF = Pars [Pars]
instance HasFontSpec EditorF

selectall :: [EditCmd]
loadEditor :: String -> [EditCmd]
setEditorCursorPos :: (Int, Int) -> [EditCmd]
data EditCmd = EditShowCursor Bool
             | EditMove EditStop IsSelect
             | EditReplace String
             | EditGetText
             | EditGetField
             | EditGetSelection
             | EditUndo
             | EditRedo

data EditEvt = EditText String
             | EditField (String, String, String)
             | EditCursor Rect
             | EditChange (InputMsg String)
instance Eq EditEvt
instance Ord EditEvt

data EditStop = EditStopFn EditStopFn | EditPoint Point | EditLine EDirection

type EditStopFn = String -> String -> EditStopChoice

data EditStopChoice = EdGo EDirection EditStopFn | EdStop

data EDirection = ELeft | ERight
instance Eq EDirection
instance Ord EDirection

Description

editorF is a multi-line text editor which supports simple text editing. Key bindings are in an Emacs-like fashion. It also supports cut/copy/paste of selections.

Input

Editor commands, such as text to edit.

Output

Editor events, for example the edited text.

data EditCmd = EditShowCursor Bool
             | EditMove EditStop IsSelect
             | EditReplace String
             | EditGetText
             | EditGetField
             | EditGetSelection
             | EditUndo
             | EditRedo
data EditEvt = EditText String
             | EditField (String, String, String)
             | EditCursor Rect
             | EditChange (InputMsg String)

EditReplace r will replace the selected text in the editor with r. The value selectall can be used to first select all the text. These two are put together in loadEditor which replaces the current text with a new text. The message setEditorCursorPos (row,col) moves the cursor to a particular row and column, which are numbered from 1 and up.

As a response to EditGetText, the editor will output its content r as EditorText r. The other constructors can be used to control the editor. (more documentation needed about this!)

Usage

The editor understands the following keys (in Emacs notation):

Cursor movements:

Arrow keys move the cursor one char, as well as C-p,C-n,C-f,C-v

M-Left,M-Right, M-f, M-b moves one word.

The cursor can also be moved with mouse button 1.

Selecting text:

By holding down Shift, the cursor movement keys will also select the text.

By Shift-clicking with mouse button 1, or dragging with mouse button 1, text is selected.

Inserting/deleting text:

By typing text, the selected text is replaced by the typed text. Pressing \key{DEL} will remove the selected text, or if no text is selected, remove the character to the left of the cursor. If no text is selected, M-\key{DEL} will delete the word to the left of the cursor.

Cut/Copy/Paste:

A menu with these commands will popup when mouse button 3 is pressed:

Cut: The selected text is made into the current selection (selection in the X Windows sense), and deleted.

Copy: The selected text is made into the current selection.

Paste: The selected text is replaced by the current selection.

Undo/Redo:

Undo: C-/. Redo: C-?

The undo buffer is by default infinite (thus producing a memory leak). This can be changed by the command line argument -undodepth. By specifying -undodepth 0, there is no undo available.