| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
NanoUI.Widgets.TextBuffer
Description
A text document as a finger tree of lines with a cursor. Every change is
a TextEdit: replace the text at a position with other text. An edit
touches only the lines it spans, so edits, cursor moves and line lookups
cost O(log lines) plus the size of the lines involved, however long the
document is.
Synopsis
- data TextBuffer = TextBuffer {
- bufferLines :: !(Seq Text)
- bufferCursor :: !Cursor
- preferredCol :: !Int
- bufferSeenHead :: !Int
- bufferSeenTail :: !Int
- data Cursor = Cursor {}
- data TextEdit = TextEdit {
- editAt :: !Cursor
- editRemoved :: !Text
- editInserted :: !Text
- empty :: TextBuffer
- fromText :: Text -> TextBuffer
- toText :: TextBuffer -> Text
- toLines :: TextBuffer -> [Text]
- lineAt :: Int -> TextBuffer -> Text
- getCursor :: TextBuffer -> Cursor
- getLineCount :: TextBuffer -> Int
- withCursor :: Cursor -> TextBuffer -> TextBuffer
- clampCursor :: TextBuffer -> Cursor -> Cursor
- changedLines :: TextBuffer -> (Int, Int)
- markLinesSeen :: TextBuffer -> TextBuffer
- moveLeft :: TextBuffer -> TextBuffer
- moveRight :: TextBuffer -> TextBuffer
- moveUp :: TextBuffer -> TextBuffer
- moveDown :: TextBuffer -> TextBuffer
- moveToBOL :: TextBuffer -> TextBuffer
- moveToEOL :: TextBuffer -> TextBuffer
- moveToTop :: TextBuffer -> TextBuffer
- moveToBottom :: TextBuffer -> TextBuffer
- moveWordLeft :: TextBuffer -> TextBuffer
- moveWordRight :: TextBuffer -> TextBuffer
- selectionRange :: Cursor -> Cursor -> (Cursor, Cursor)
- selectedText :: Cursor -> Cursor -> TextBuffer -> Text
- textRange :: Cursor -> Cursor -> TextBuffer -> Text
- documentEnd :: TextBuffer -> Cursor
- applyEdit :: TextEdit -> TextBuffer -> TextBuffer
- invertEdit :: TextEdit -> TextEdit
- replaceEdit :: Text -> Cursor -> Cursor -> TextBuffer -> TextEdit
- insertableText :: Text -> Text
Types
data TextBuffer Source #
Lines (never empty, and without their newlines) and the cursor.
Constructors
| TextBuffer | |
Fields
| |
Instances
| Eq TextBuffer Source # | |
Defined in NanoUI.Widgets.TextBuffer | |
| Show TextBuffer Source # | |
Defined in NanoUI.Widgets.TextBuffer Methods showsPrec :: Int -> TextBuffer -> ShowS # show :: TextBuffer -> String # showList :: [TextBuffer] -> ShowS # | |
Zero-indexed logical (row, column) position in the buffer. Fields are
row then column, so the derived Ord is document order.
Replace editRemoved at editAt with editInserted. Both texts may
span lines. An edit carries what it removes, so it can be inverted without
looking at the document.
Constructors
| TextEdit | |
Fields
| |
Construction & Conversion
empty :: TextBuffer Source #
A TextBuffer containing a single blank line.
fromText :: Text -> TextBuffer Source #
Construct a TextBuffer from raw Text. Cursor is always (0, 0).
toText :: TextBuffer -> Text Source #
All lines joined with newlines, copied once into a new text.
toLines :: TextBuffer -> [Text] Source #
Cursor & Metrics
getCursor :: TextBuffer -> Cursor Source #
getLineCount :: TextBuffer -> Int Source #
withCursor :: Cursor -> TextBuffer -> TextBuffer Source #
Move to a position, clamped into the document, without changing text.
clampCursor :: TextBuffer -> Cursor -> Cursor Source #
The nearest position inside the document.
changedLines :: TextBuffer -> (Int, Int) Source #
How many lines at the start and at the end are the ones there at the last
markLinesSeen; the lines between may have changed. Whatever was derived
per line from the marked document can be kept for those lines and
rederived for the rest.
markLinesSeen :: TextBuffer -> TextBuffer Source #
Record that every line has been seen, for changedLines.
Navigation
moveLeft :: TextBuffer -> TextBuffer Source #
moveRight :: TextBuffer -> TextBuffer Source #
moveUp :: TextBuffer -> TextBuffer Source #
moveDown :: TextBuffer -> TextBuffer Source #
moveToBOL :: TextBuffer -> TextBuffer Source #
moveToEOL :: TextBuffer -> TextBuffer Source #
moveToTop :: TextBuffer -> TextBuffer Source #
moveToBottom :: TextBuffer -> TextBuffer Source #
moveWordLeft :: TextBuffer -> TextBuffer Source #
Back over spaces (line breaks count), then over the word before them.
moveWordRight :: TextBuffer -> TextBuffer Source #
Forward over spaces (line breaks count), then over the word after them.
Selection
selectedText :: Cursor -> Cursor -> TextBuffer -> Text Source #
textRange :: Cursor -> Cursor -> TextBuffer -> Text Source #
The text between two positions in document order, reading only the lines between them.
documentEnd :: TextBuffer -> Cursor Source #
Edits
applyEdit :: TextEdit -> TextBuffer -> TextBuffer Source #
Apply an edit and leave the cursor after the inserted text. The removed text decides how far the edit reaches, so an edit recorded against this document (or undone from one) is applied without reading the text it removes.
invertEdit :: TextEdit -> TextEdit Source #
The edit that takes the document back.
replaceEdit :: Text -> Cursor -> Cursor -> TextBuffer -> TextEdit Source #
The edit replacing the text between two positions.
insertableText :: Text -> Text Source #
Text as it can enter the document: printable characters, tabs and line breaks, with Windows line ends folded.