GTK has a powerful framework for multiline text editing.
Figure: GtkTextView
The primary objects involved in the process are the
gtk:text-buffer object, which represents the text being edited, and the
gtk:text-view widget, a widget which can display a
gtk:text-buffer object. Each text
buffer can be displayed by any number of views.
CSS nodes
textview.view
├── border.top
├── border.left
├── text
│ ╰── [selection]
├── border.right
├── border.bottom
╰── [window.popup]
The
gtk:text-view implementation has a main CSS node with name
textview and
.view style class, and subnodes for each of the border windows, and the main text area, with names
border and
text, respectively. The border nodes each get one of the
.left,
.right,
.top or
.bottom style classes.
A node representing the selection will appear below the text node. If a
context menu is opened, the window node will appear as a subnode of the
main node.
Accessibility
The
gtk:text-view implmementation uses the
:text-box role of the
gtk:accessible-role enumeration.
Signal Details
The "backspace" signal
lambda (view) :action
- view
- The gtk:text-view widget which received the signal.
The signal is a keybinding signal which gets emitted when the user asks for it. The default bindings for this signal are the
Backspace and
Shift-Backspace keys.
The "copy-clipboard" signal
lambda (view) :action
- view
- The gtk:text-view widget which received the signal.
The signal is a keybinding signal which gets emitted to copy the
selection to the clipboard. The default bindings for this signal are the
Ctrl-c and
Ctrl-Insert keys.
The "cut-clipboard" signal
lambda (view) :action
- view
- The gtk:text-view widget which received the signal.
The signal is a keybinding signal which gets emitted to cut the selection
to the clipboard. The default bindings for this signal are the
Ctrl-x and
Shift-Delete keys.
The "delete-from-cursor" signal
lambda (view granularity count) :action
- view
- The gtk:text-view widget which received the signal.
- granularity
- The granularity of the deletion, as a value of the gtk:delete-type enumeration.
- count
- The integer with the number of type units to delete.
The signal is a keybinding signal which gets emitted when the user initiates a text deletion. If the granularity is
:chars, GTK
deletes the selection if there is one, otherwise it deletes the requested
number of characters. The default bindings for this signal are the
Delete key for deleting a character, the
Ctrl-Delete key for deleting a word and the
Ctrl-Backspace key for deleting a word
backwords.
The "extend-selection" signal
lambda (view granularity location start end) :run-last
- view
- The gtk:text-view widget which received the signal.
- granularity
- The granularity as a value of the gtk:text-extend-selection enumeration.
- location
- The gtk:text-iter iterator where to extend the selection.
- start
- The gtk:text-iter iterator where the selection should start.
- end
- The gtk:text-iter iterator where the selection should end.
- Returns
- True to stop other handlers from being invoked for the event, false to propagate the event further.
The signal is emitted when the selection needs to be extended at the
location iterator.
The "insert-at-cursor" signal
lambda (view text) :action
- view
- The gtk:text-view widget which received the signal.
- text
- The string with the text to insert.
The signal is a keybinding signal which gets emitted when the user
initiates the insertion of text at the cursor. The signal has no default
bindings.
The "insert-emoji" signal
lambda (view) :action
- view
- The gtk:text-view widget which received the signal.
This signal is a keybinding signal which gets emitted to present the Emoji
chooser for the text view. The default bindings for this signal are
Ctrl-. and
Ctrl-;.
The "move-cursor" signal
lambda (view step count extend) :action
- view
- The gtk:text-view widget which received the signal.
- step
- The granularity of the move, as a value of the gtk:movement-step enumeration.
- count
- The integer with the number of step units to move.
- extend
- True if the move should extend the selection.
The signal is a keybinding signal which gets emitted when the user
initiates a cursor movement. If the cursor is not visible in the text
view, this signal causes the viewport to be moved instead. Applications should not connect to it, but may emit it with the
g:signal-emit
function if they need to control the cursor programmatically. The default
bindings for this signal come in two variants, the variant with the
Shift modifier extends the selection, the variant without the
Shift modifer does not. There are too many key combinations to list
them all here. Arrow keys move by individual characters/lines. The
Ctrl-arrow key combinations move by words/paragraphs. The
Home/
End keys move to the ends of the text buffer. The
PageUp/
PageDown keys move vertically by pages. The
Ctrl-PageUp/
PageDown keys move horizontally by pages.
The "move-viewport" signal
lambda (view step count) :action
- view
- The gtk:text-view widget which received the signal.
- step
- The granularity of the move, as a value of the gtk:movement-step enumeration.
- count
- The integer with the number of step units to move.
The signal is a keybinding signal which can be bound to key combinations
to allow the user to move the viewport, that is, to change what part of
the text view is visible in a scrolled window. There are no default
bindings for this signal.
The "paste-clipboard" signal
lambda (view) :action
- view
- The gtk:text-view widget which received the signal.
The signal is a keybinding signal which gets emitted to paste the
contents of the clipboard into the text view. The default bindings for this signal are the
Ctrl-v and
Shift-Insert keys.
The "preedit-changed" signal
lambda (view preedit) :action
- view
- The gtk:text-view object which received the signal.
- preedit
- The string with the current preedit text.
If an input method is used, the typed text will not immediately be
committed to the text buffer. So if you are interested in the text,
connect to this signal. The signal is only emitted if the text at the
given position is actually editable.
The "select-all" signal
lambda (view select) :action
- view
- The gtk:text-view widget which received the signal.
- select
- True to select, false to unselect.
The signal is a keybinding signal which gets emitted to select or unselect
the complete contents of the text view. The default bindings for the signal are the
Ctrl-a and
Ctrl-/ keys for selecting and the
Shift-Ctrl-a and
Ctrl- keys for unselecting.
The "set-anchor" signal
lambda (view) :action
- view
- The gtk:text-view widget which received the signal.
The signal is a keybinding signal which gets emitted when the user
initiates setting the "anchor" mark. The "anchor" mark gets placed at
the same position as the "insert" mark. The signal has no default
bindings.
The "toggle-cursor-visible" signal
lambda (view) :action
- view
- The gtk:text-view widget which received the signal.
This signal is a keybinding signal which gets emitted to toggle the visibility of the cursor. The default binding for this signal is
F7.
The "toggle-overwrite" signal
lambda (view) :action
- view
- The gtk:text-view widget which received the signal.
The signal is a keybinding signal which gets emitted to toggle the
overwrite mode of the text view. The default bindings for this signal is the
Insert key.