Displays the contents of a [class@Gtk.
TextBuffer].
<picture> <source srcset="multiline-text-dark.png" media="(prefers-color-scheme: dark)"> <img alt="An example
GtkTextView" src="multiline-text.png"> </picture>
You may wish to begin by reading the [conceptual overview](section-text-widget.html), which gives an overview of all the objects and data
types related to the text widget and how they work together.
Shortcuts and Gestures
`GtkTextView` supports the following keyboard shortcuts:
- <kbd>Shift</kbd>+<kbd>F10</kbd> or <kbd>Menu</kbd> opens the context menu.
- <kbd>Ctrl</kbd>+<kbd>Z</kbd> undoes the last modification.
- <kbd>Ctrl</kbd>+<kbd>Y</kbd> or <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>Z</kbd
> redoes the last undone modification.
- <kbd>Clear</kbd> clears the content.
Additionally, the following signals have default keybindings:
- [signal@Gtk.TextView:
GtkTextView:backspace]
- [signal@Gtk.TextView:
GtkTextView:copy-clipboard]
- [signal@Gtk.TextView:
GtkTextView:cut-clipboard]
- [signal@Gtk.TextView:
GtkTextView:delete-from-cursor]
- [signal@Gtk.TextView:
GtkTextView:insert-emoji]
- [signal@Gtk.TextView:
GtkTextView:move-cursor]
- [signal@Gtk.TextView:
GtkTextView:paste-clipboard]
- [signal@Gtk.TextView:
GtkTextView:select-all]
- [signal@Gtk.TextView:
GtkTextView:toggle-cursor-visible]
- [signal@Gtk.TextView:
GtkTextView:toggle-overwrite]
Actions
`GtkTextView` defines a set of built-in actions:
- `clipboard.copy` copies the contents to the clipboard.
- `clipboard.cut` copies the contents to the clipboard and deletes it from the widget.
- `clipboard.paste` inserts the contents of the clipboard into the widget.
- `menu.popup` opens the context menu.
- `misc.insert-emoji` opens the Emoji chooser.
- `selection.delete` deletes the current selection.
- `selection.select-all` selects all of the widgets content.
- `text.redo` redoes the last change to the contents.
- `text.undo` undoes the last change to the contents.
- `text.clear` clears the content.
CSS nodes
``` textview.view ├── border.top ├── border.left ├── text │ ╰── [selection] ├── border.right ├──
border.bottom ╰── [window.popup] ```
`GtkTextView` has a main css node with name textview and style class .view, 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 style classes .left, .right, .top or .bottom.
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
`GtkTextView` uses the [enum@Gtk.AccessibleRole.text_box] role.
- public bool accepts_tab { get; set; }
Whether Tab will result in a tab character being entered.
- public TextBuffer buffer { get; set; }
The buffer which is displayed.
- public bool cursor_visible { get; set; }
If the insertion cursor is shown.
- public bool editable { get; set; }
Whether the text can be modified by the user.
- public string im_module { owned get; set; }
Which IM (input method) module should be used for this text_view.
- public int indent { get; set; }
Amount to indent the paragraph, in pixels.
- public Justification justification { get; set; }
Left, right, or center justification.
- public int left_margin { get; set; }
The default left margin for text in the text view.
- public bool overwrite { get; set; }
Whether entered text overwrites existing contents.
- public int pixels_above_lines { get; set; }
Pixels of blank space above paragraphs.
- public int pixels_below_lines { get; set; }
Pixels of blank space below paragraphs.
- public int pixels_inside_wrap { get; set; }
Pixels of blank space between wrapped lines in a paragraph.
- public int right_margin { get; set; }
The default right margin for text in the text view.
- public TabArray tabs { owned get; set; }
Custom tabs for this text.
- public WrapMode wrap_mode { get; set; }
Whether to wrap lines never, at word boundaries, or at character
boundaries.
- public void add_child_at_anchor (Widget child, TextChildAnchor anchor)
Adds a child widget in the text buffer, at the given anchor
.
- public void add_child_in_window (Widget child, TextWindowType which_window, int xpos, int ypos)
Adds a child at fixed coordinates in one of the text widget's windows.
- public bool backward_display_line (ref TextIter iter)
Moves the given iter backward by one display (wrapped)
line.
- public bool backward_display_line_start (ref TextIter iter)
Moves the given iter backward to the next display line
start.
- public void buffer_to_window_coords (TextWindowType win, int buffer_x, int buffer_y, out int window_x, out int window_y)
Converts buffer coordinates to window coordinates.
- public bool forward_display_line (ref TextIter iter)
Moves the given iter forward by one display (wrapped)
line.
- public bool forward_display_line_end (ref TextIter iter)
Moves the given iter forward to the next display line
end.
- public bool get_accepts_tab ()
Returns whether pressing the <kbd>Tab</kbd> key inserts a
tab characters.
- public int get_border_window_size (TextWindowType type)
Gets the width of the specified border window.
- public unowned TextBuffer get_buffer ()
Returns the `GtkTextBuffer` being displayed by this text view.
- public bool get_cursor_visible ()
Find out whether the cursor should be displayed.
- public TextAttributes get_default_attributes ()
Obtains a copy of the default text attributes.
- public bool get_editable ()
Returns the default editability of the `GtkTextView`.
- public unowned Adjustment get_hadjustment ()
- public int get_indent ()
Gets the default indentation of paragraphs in
this.
- public void get_iter_at_location (out TextIter iter, int x, int y)
Retrieves the iterator at buffer coordinates x and
y.
- public void get_iter_at_position (out TextIter iter, out int trailing, int x, int y)
Retrieves the iterator pointing to the character at buffer coordinates
x and y.
- public void get_iter_location (TextIter iter, out Rectangle location)
Gets a rectangle which roughly contains the character at iter
.
- public Justification get_justification ()
Gets the default justification of paragraphs in
this.
- public int get_left_margin ()
Gets the default left margin size of paragraphs in the
this.
- public void get_line_at_y (out TextIter target_iter, int y, out int line_top)
Gets the `GtkTextIter` at the start of the line containing the
coordinate y.
- public void get_line_yrange (TextIter iter, out int y, out int height)
Gets the y coordinate of the top of the line containing iter
, and the height of the line.
- public bool get_overwrite ()
Returns whether the `GtkTextView` is in overwrite mode or not.
- public int get_pixels_above_lines ()
Gets the default number of pixels to put above paragraphs.
- public int get_pixels_below_lines ()
Gets the default number of pixels to put below paragraphs.
- public int get_pixels_inside_wrap ()
Gets the default number of pixels to put between wrapped lines inside
a paragraph.
- public int get_right_margin ()
Gets the default right margin for text in
this.
- public TabArray get_tabs ()
Gets the default tabs for this.
- public unowned Adjustment get_vadjustment ()
- public void get_visible_rect (out Rectangle visible_rect)
Fills visible_rect with the currently-visible region of
the buffer, in buffer coordinates.
- public unowned Window get_window (TextWindowType win)
Retrieves the
Window corresponding to an area of the text view; possible windows include the overall widget window, child windows on the left,
right, top, bottom, and the window that displays the text buffer.
- public TextWindowType get_window_type (Window window)
Usually used to find out which window an event corresponds to.
- public WrapMode get_wrap_mode ()
Gets the line wrapping for the view.
- public bool im_context_filter_keypress (EventKey event)
Allow the `GtkTextView` input method to internally handle key press
and release events.
- public void move_child (Widget child, int xpos, int ypos)
- public virtual void move_focus (DirectionType direction)
- public bool move_mark_onscreen (TextMark mark)
Moves a mark within the buffer so that it's located within the
currently-visible text area.
- public bool move_visually (ref TextIter iter, int count)
Move the iterator a given number of characters visually, treating it
as the strong cursor position.
- public bool place_cursor_onscreen ()
Moves the cursor to the currently visible region of the buffer.
- public void reset_im_context ()
Reset the input method context of the text view if needed.
- public void scroll_mark_onscreen (TextMark mark)
Scrolls this the minimum distance
such that mark is contained within the visible area of the widget.
- public bool scroll_to_iter (TextIter iter, double within_margin, bool use_align, double xalign, double yalign)
Scrolls this so that iter
is on the screen in the position indicated by xalign and yalign.
- public void scroll_to_mark (TextMark mark, double within_margin, bool use_align, double xalign, double yalign)
Scrolls this so that mark
is on the screen in the position indicated by xalign and yalign.
- public void set_accepts_tab (bool accepts_tab)
Sets the behavior of the text widget when the <kbd>Tab</kbd
> key is pressed.
- public void set_border_window_size (TextWindowType type, int size)
Sets the width of gtk_text_window_left
or gtk_text_window_right, or the height of gtk_text_window_top
or gtk_text_window_bottom.
- public void set_buffer (TextBuffer buffer)
Sets buffer as the buffer being displayed by
this.
- public void set_cursor_visible (bool setting)
Toggles whether the insertion point should be displayed.
- public void set_editable (bool setting)
Sets the default editability of the `GtkTextView`.
- public void set_indent (int indent)
Sets the default indentation for paragraphs in
this.
- public void set_justification (Justification justification)
Sets the default justification of text in
this.
- public void set_left_margin (int left_margin)
Sets the default left margin for text in
this.
- public void set_overwrite (bool overwrite)
Changes the `GtkTextView` overwrite mode.
- public void set_pixels_above_lines (int pixels_above_lines)
Sets the default number of blank pixels above paragraphs in
this.
- public void set_pixels_below_lines (int pixels_below_lines)
Sets the default number of pixels of blank space to put below
paragraphs in this.
- public void set_pixels_inside_wrap (int pixels_inside_wrap)
Sets the default number of pixels of blank space to leave between
display/wrapped lines within a paragraph.
- public void set_right_margin (int right_margin)
Sets the default right margin for text in the text view.
- public void set_tabs (TabArray tabs)
Sets the default tab stops for paragraphs in
this.
- public void set_wrap_mode (WrapMode wrap_mode)
Sets the line wrapping for the view.
- public bool starts_display_line (TextIter iter)
Determines whether iter is at the start of a display
line.
- public void window_to_buffer_coords (TextWindowType win, int window_x, int window_y, out int buffer_x, out int buffer_y)
Converts coordinates on the window identified by win to
buffer coordinates.
- public virtual signal void backspace ()
Gets emitted when the user asks for it.
- public virtual signal void copy_clipboard ()
Gets emitted to copy the selection to the clipboard.
- public virtual signal void cut_clipboard ()
Gets emitted to cut the selection to the clipboard.
- public virtual signal void delete_from_cursor (DeleteType type, int count)
Gets emitted when the user initiates a text deletion.
- public virtual signal void insert_at_cursor (string str)
Gets emitted when the user initiates the insertion of a fixed string
at the cursor.
- public virtual signal void move_cursor (MovementStep step, int count, bool extend_selection)
Gets emitted when the user initiates a cursor movement.
- public virtual signal void move_viewport (ScrollStep p0, int p1)
Gets emitted to move the viewport.
- public virtual signal void page_horizontally (int count, bool extend_selection)
- public virtual signal void paste_clipboard ()
Gets emitted to paste the contents of the clipboard into the text
view.
- public virtual signal void populate_popup (Menu menu)
The populate_popup signal gets emitted
before showing the context menu of the text view.
- public virtual signal void preedit_changed (string p0)
Emitted when preedit text of the active IM changes.
- public virtual signal void select_all (bool p0)
Gets emitted to select or unselect the complete contents of the text
view.
- public virtual signal void set_anchor ()
Gets emitted when the user initiates settings the "anchor" mark.
- public virtual signal void set_scroll_adjustments (Adjustment hadjustment, Adjustment vadjustment)
- public virtual signal void toggle_cursor_visible ()
Gets emitted to toggle the `cursor-visible` property.
- public virtual signal void toggle_overwrite ()
Gets emitted to toggle the overwrite mode of the text view.