nano-ui
Safe HaskellNone
LanguageGHC2024

NanoUI.Widgets.TextEditor

Description

The editing core every text field shares: a document, a selection and an undo history, changed only by TextCommands. Keys and menu rows map onto commands, and an app can run the same commands on a field.

Synopsis

Commands

data TextCommand Source #

Something done to a text field. Commands that change text are undoable and replace the selection where one exists.

Constructors

InsertText !Text

Replace the selection with text (typing, a snippet).

Delete !TextMotion

Delete the selection, or from the cursor to where the motion lands: Delete CharLeft is Backspace, Delete WordRight Ctrl+Delete.

Move !TextMotion !Bool

Move the cursor, extending the selection when the flag is set.

SelectAll 
Select !Cursor !Cursor

Select from the first position (the anchor) to the second (the cursor), clamped into the document.

Replace !Cursor !Cursor !Text

Replace the text between two positions, leaving the cursor after it.

ReplaceAll !Text

Replace the whole document as one undoable edit.

Undo 
Redo 
Cut 
Copy 
Paste 

Instances

Instances details
Eq TextCommand Source # 
Instance details

Defined in NanoUI.Widgets.TextCommand

Show TextCommand Source # 
Instance details

Defined in NanoUI.Widgets.TextCommand

Editors

data Editor Source #

A document with its selection (the cursor is the buffer's, the anchor the other end) and history.

Instances

Instances details
Show Editor Source # 
Instance details

Defined in NanoUI.Widgets.TextEditor

data EditorMode Source #

How a field lets its document be changed.

Constructors

EditorMode 

Fields

Instances

Instances details
Eq EditorMode Source # 
Instance details

Defined in NanoUI.Widgets.TextEditor

Show EditorMode Source # 
Instance details

Defined in NanoUI.Widgets.TextEditor

editorModeCode :: EditorMode -> Int Source #

A mode as a store integer, so a command sent to a widget id between frames knows what kind of field it edits.

editorSelection :: Editor -> (Cursor, Cursor) Source #

(anchor, cursor).

runCommand :: EditorMode -> TextCommand -> Editor -> Editor Source #

Run a command that needs no clipboard. Cut, Copy and Paste do nothing here; runCommandIO runs them.

runCommandIO :: Context -> EditorMode -> TextCommand -> Editor -> IO Editor Source #

runCommand, with the clipboard commands going through the context's clipboard.

Key bindings

inputTextCommands :: EditorMode -> Input -> [TextCommand] Source #

This frame's typing and keys as commands, typed characters first. Ctrl turns characters into shortcuts. Ctrl with Alt is AltGr on many layouts, so its characters are typed like plain ones.

keyCommand :: EditorMode -> Modifiers -> Key -> Maybe TextCommand Source #

The command a key runs. Ctrl or Alt turns character and deletion keys into word motions, and Shift extends the selection.

History

data EditHistory Source #

Constructors

EditHistory 

Fields

Instances

Instances details
Eq EditHistory Source # 
Instance details

Defined in NanoUI.Widgets.TextEditor

Show EditHistory Source # 
Instance details

Defined in NanoUI.Widgets.TextEditor

data EditGroup Source #

Edits undone and redone as one step.

Constructors

EditGroup 

Fields

Instances

Instances details
Eq EditGroup Source # 
Instance details

Defined in NanoUI.Widgets.TextEditor

Show EditGroup Source # 
Instance details

Defined in NanoUI.Widgets.TextEditor

data StoredEdit Source #

An edit as history keeps it. Undo steps live for the life of a field and are rarely replayed, so their texts are compact copies: they cost two words less than a Text, and never keep alive the larger text a slice was cut from.

Instances

Instances details
Eq StoredEdit Source # 
Instance details

Defined in NanoUI.Widgets.TextEditor

Show StoredEdit Source # 
Instance details

Defined in NanoUI.Widgets.TextEditor

data EditKind Source #

What started a group of edits, which decides what may join it.

Instances

Instances details
Eq EditKind Source # 
Instance details

Defined in NanoUI.Widgets.TextEditor

Show EditKind Source # 
Instance details

Defined in NanoUI.Widgets.TextEditor

sealHistory :: EditHistory -> EditHistory Source #

Start the next edit in a group of its own.