NAME
TUI::Editors::Editor - multi-line text editor view
HIERARCHY
TObject
TView
TEditor
SYNOPSIS
use TUI::Objects;
use TUI::Editors;
my $editor = new_TEditor(
TRect->new( ax => 0, ay => 0, bx => 80, by => 24 ),
undef,
undef,
undef,
1024,
);
$editor->insertText( 'Hello, world!', 13, 0 );
DESCRIPTION
TEditor is a view that edits a text buffer. Lines may end with CR, LF or CR LF (a CR LF pair counts as one line break for cursor movement). The buffer is a native Perl string; positions are character positions.
Undo, clipboard (clipCopy, clipCut, clipPaste) and search and replace (find, replace, search) are available. The bufSize argument is stored but not enforced, because the Perl buffer grows as needed.
The buffer and line helpers (bufChar, bufPtr, formatLine, lineEnd, lineStart, nextChar, nextLine, prevChar, prevLine) are documented in TUI::Editors::Editor::Edits.
VARIABLES
The following global variables hold the search, replace and clipboard state shared by all editors.
$clipboard
The editor that holds the clipboard contents.
$editorDialog
Dialog callback, a dummy until TEditorDialog is ported.
$editorFlags
Search and replace option flags.
$findStr
Last search text.
$replaceStr
Last replacement text.
ATTRIBUTES
buffer
Text buffer (Str).
bufSize
Size of the buffer (Int). It is stored but not enforced, because the Perl buffer grows as needed.
hScrollBar
Horizontal scroll bar (TScrollBar or undef).
vScrollBar
Vertical scroll bar (TScrollBar or undef).
indicator
Position indicator (TIndicator or undef).
selStart
Start of the selection (PositiveOrZeroInt).
selEnd
End of the selection (PositiveOrZeroInt).
curPtr
Current cursor position (PositiveOrZeroInt).
curPos
Current cursor position as a point (TPoint).
delta
Delta for scrolling (TPoint).
limit
Limit for scrolling (TPoint).
drawLine
Line to draw (Int).
drawPtr
Draw pointer (PositiveOrZeroInt).
delCount
Delete count (PositiveOrZeroInt).
insCount
Insert count (Int).
isValid
Indicates whether the editor is valid (Bool).
canUndo
Indicates whether undo is enabled (Bool).
modified
Indicates whether the buffer has been modified (Bool).
selecting
Indicates whether text is being selected (Bool).
overwrite
Indicates whether overwrite mode is enabled (Bool).
autoIndent
Indicates whether auto-indent is enabled (Bool).
lockCount
Lock count (PositiveOrZeroInt).
updateFlags
Update flags (PositiveOrZeroInt).
keyState
Key state (Int).
CONSTRUCTOR
new
my $editor = TEditor->new(
bounds => $bounds,
hScrollBar => $hScrollBar, # or undef
vScrollBar => $vScrollBar, # or undef
indicator => $indicator, # or undef,
bufSize => $bufSize,
);
Creates a new editor with the specified buffer size.
- bounds
-
Bounding rectangle of the view (TRect).
- hScrollBar
-
Optional horizontal scroll bar (TScrollBar or
undef). - vScrollBar
-
Optional vertical scroll bar (TScrollBar or
undef). - indicator
-
Optional position indicator (TIndicator or
undef). - bufSize
-
Buffer size (PositiveOrZeroInt).
new_TEditor
my $editor = new_TEditor(
$bounds,
$hScrollBar, # or undef
$vScrollBar, # or undef
$indicator, # or undef
$bufSize,
);
Factory-style constructor using positional arguments.
METHODS
bufLen
my $len = $editor->bufLen;
Returns the length of the buffer in characters.
changeBounds
$editor->changeBounds($bounds);
Sets new bounds and clamps the scroll position to the new size.
charPos
my $col = $editor->charPos($p, $target);
Returns the display column of the character at buffer position $p when the line is read up to $target. Tabs advance to the next tab stop.
charPtr
my $pos = $editor->charPtr($p, $target);
Returns the buffer position of the display column $target on the line that starts at $p.
checkScrollBar
$editor->checkScrollBar($event, $scrollBar, $value);
Checks whether the scroll bar $scrollBar was moved by the event $event. If so, $value is set to the new position of the scroll bar and the view is marked for redrawing. $value is passed by alias, so pass a variable, not a literal.
clipCopy
my $ok = $editor->clipCopy;
Copies the selection into the clipboard editor. Returns false if no clipboard is set or if this editor is the clipboard itself.
clipCut
$editor->clipCut;
Copies the selection to the clipboard and deletes it.
clipPaste
$editor->clipPaste;
Inserts the contents of the clipboard at the cursor.
convertEvent
$editor->convertEvent($event);
Converts key events into command events, including the Ctrl-Q quick keys and the Ctrl-K block keys.
cursorVisible
my $bool = $editor->cursorVisible;
Returns true if the cursor lies inside the visible part of the editor.
deleteRange
$editor->deleteRange($startPtr, $endPtr, $delSelect);
Deletes the text between the two buffer positions. If $delSelect is true, the selection is cleared as well.
deleteSelect
$editor->deleteSelect;
Deletes the selected text.
doneBuffer
$editor->doneBuffer;
Releases the buffer; the buffer is set to undef.
doSearchReplace
$editor->doSearchReplace;
Performs a search for $findStr with the options in $editorFlags. If the replace options are set, it also replaces the match, asking through $editorDialog when prompting is enabled. It repeats while efReplaceAll is set.
doUpdate
$editor->doUpdate;
Redraws the parts of the view marked in updateFlags, updates the scroll bars and the indicator, and clears the flags. update calls it when the editor is not locked.
draw
$editor->draw;
Draws the visible part of the editor.
drawLines
$editor->drawLines($y, $count, $linePtr);
Draws $count lines starting at row $y of the view. The first line starts at buffer position $linePtr.
find
$editor->find;
Asks the user for a search string and searches for it.
getMousePtr
my $index = $editor->getMousePtr($where);
Returns the buffer position under the mouse location $where.
getPalette
my $palette = $editor->getPalette;
Returns the palette used by the editor.
handleEvent
$editor->handleEvent($event);
Handles keyboard, mouse and command events.
hasSelection
my $bool = $editor->hasSelection;
Returns true if some text is selected.
hideSelect
$editor->hideSelect;
Clears the selection and keeps the cursor at its position.
initBuffer
$editor->initBuffer;
Initializes an empty buffer.
insertBuffer
my $ok = $editor->insertBuffer(
$text, $offset, $length, $allowUndo, $selectText);
Inserts the $length characters of $text starting at $offset at the cursor. assert checks that the slice lies within $text. If $selectText is true, the inserted text becomes the selection.
insertFrom
my $ok = $editor->insertFrom($editor);
Inserts the selected text of another editor at the cursor.
insertText
my $ok = $editor->insertText($text, $length, $selectText);
Inserts $text at the cursor, using undo information if canUndo is set. $length is the length of $text, which is checked with assert.
isClipboard
my $bool = $editor->isClipboard;
Returns true if this editor is the clipboard editor.
lineMove
my $pos = $editor->lineMove($p, $count);
Moves $count lines up or down from buffer position $p, keeping the column, and returns the new position.
lock
$editor->lock;
Increments the lock count. See unlock.
newLine
$editor->newLine;
Inserts a line break at the cursor, using the indentation of the current line when auto-indent is on.
nextWord
my $pos = $editor->nextWord($p);
Returns the position of the start of the next word after $p.
prevWord
my $pos = $editor->prevWord($p);
Returns the position of the start of the previous word before $p.
replace
$editor->replace;
Asks the user for a search and replace string and replaces the matches.
scrollTo
$editor->scrollTo($x, $y);
Scrolls the visible area so that the position ($x, $y) is shown, within the limits of the buffer.
search
my $bool = $editor->search($findStr, $opts);
Searches for $findStr from the cursor position. $opts is a bit mask of search options. Returns true if a match was found and selected.
setBufLen
$editor->setBufLen($length);
Sets the buffer length and resets the cursor, the selection and the scroll position.
setBufSize
my $bool = $editor->setBufSize($newSize);
Stores the buffer size. It always returns true, because the buffer is not limited by a capacity.
setCmdState
$editor->setCmdState($command, $enable);
Enables or disables a single command. Commands are enabled only while the editor is active (sfActive); otherwise they are disabled. Use this instead of the TView variant, which takes a command set.
setCurPtr
$editor->setCurPtr($p, $selectMode);
Moves the cursor to buffer position $p. If $selectMode is true, the selection is extended.
setSelect
$editor->setSelect($newStart, $newEnd, $curStart);
Sets the selection range and the cursor. Moving the cursor resets the undo counters.
setState
$editor->setState($aState, $enable);
Sets or clears a state flag. Changing sfActive shows or hides the scroll bars and the indicator and updates the commands. Enabling sfExposed unlocks the editor.
shutDown
$editor->shutDown;
Releases the buffer and shuts down the view.
startSelect
$editor->startSelect;
Starts a selection at the cursor position.
toggleInsMode
$editor->toggleInsMode;
Toggles between insert and overwrite mode.
trackCursor
$editor->trackCursor($center);
Scrolls the view so that the cursor is visible. If $center is true, the cursor is centered.
undo
$editor->undo;
Undoes the last change, if undo is enabled.
unlock
$editor->unlock;
Decrements the lock count and updates the view when it reaches zero.
update
$editor->update($aFlags);
Marks the view for redrawing according to the update flags $aFlags.
updateCommands
$editor->updateCommands;
Enables or disables the editing commands according to the editor state.
valid
my $bool = $editor->valid($command);
Returns the validity flag of the editor.
STRUCTURES
TFindDialogRec and TReplaceDialogRec are the data records of the search and replace dialogs. They are built with Class::Struct as array references, and they are used by the find and replace methods.
TFindDialogRechas the attributesfind(the search text) andoptions(the editor flags).TReplaceDialogRechas the attributesfind(the search text),replace(the replacement text) andoptions(the editor flags).
my $findRec = TFindDialogRec->new( find => 'text', options => 0 );
SEE ALSO
TUI::Editors, TUI::Editors::Editor::Edits, TView
AUTHORS
Borland International (original Turbo Vision design)
J. Schneider <brickpool@cpan.org> (Perl implementation and maintenance)
COPYRIGHT AND LICENSE
Copyright (c) 1990-1994, 1997 by Borland International
Copyright (c) 2026 the "AUTHORS" as listed above.
This software is licensed under the MIT license (see the LICENSE file, which is part of the distribution).