Skip to content

LineEdit

Inherits: Control < CanvasItem < Entity < Object

An input field for single-line text.

LineEdit provides an input field for editing a single line of text.

While entering text, it is possible to insert special characters using Unicode, OEM or Windows alt codes:

  • To enter Unicode codepoints, hold Alt and type the codepoint on the numpad. For example, to enter the character á (U+00E1), hold Alt and type +E1 on the numpad (the leading zeroes can be omitted).

  • To enter OEM codepoints, hold Alt and type the code on the numpad. For example, to enter the character á (OEM 160), hold Alt and type 160 on the numpad.

  • To enter Windows codepoints, hold Alt and type the code on the numpad. For example, to enter the character á (Windows 0225), hold Alt and type 0, 2, 2, 5 on the numpad. The leading zero here must not be omitted, as this is how Windows codepoints are distinguished from OEM codepoints.

Important:

  • Focusing the LineEdit with ui_focus_next (by default Tab) or ui_focus_prev (by default Shift + Tab) or Control.grab_focus() still enters edit mode (for compatibility).

LineEdit features many built-in shortcuts that are always available (Ctrl here maps to Cmd on macOS):

  • Ctrl + C: Copy

  • Ctrl + X: Cut

  • Ctrl + V or Ctrl + Y: Paste/“yank”

  • Ctrl + Z: Undo

  • Ctrl + ~: Swap input direction.

  • Ctrl + Shift + Z: Redo

  • Ctrl + U: Delete text from the caret position to the beginning of the line

  • Ctrl + K: Delete text from the caret position to the end of the line

  • Ctrl + A: Select all text

  • Up Arrow/Down Arrow: Move the caret to the beginning/end of the line

On macOS, some extra keyboard shortcuts are available:

  • Cmd + F: Same as Right Arrow, move the caret one character right

  • Cmd + B: Same as Left Arrow, move the caret one character left

  • Cmd + P: Same as Up Arrow, move the caret to the previous line

  • Cmd + N: Same as Down Arrow, move the caret to the next line

  • Cmd + D: Same as Delete, delete the character on the right side of caret

  • Cmd + H: Same as Backspace, delete the character on the left side of the caret

  • Cmd + A: Same as Home, move the caret to the beginning of the line

  • Cmd + E: Same as End, move the caret to the end of the line

  • Cmd + Left Arrow: Same as Home, move the caret to the beginning of the line

  • Cmd + Right Arrow: Same as End, move the caret to the end of the line

Note: Caret movement shortcuts listed above are not affected by shortcut_keys_enabled.

[note]Column numbers are zero-based, like elements of an array. For example, caret_column being 0 indicates the caret is on the first column (i.e., before the first character).[/note]

Type Name Default
HorizontalAlignment alignment 0
bool backspace_deletes_composite_character_enabled false
bool caret_blink false
float caret_blink_interval 0.65
int caret_column 0
bool caret_force_displayed false
bool caret_mid_grapheme false
bool clear_button_enabled false
bool context_menu_enabled true
bool deselect_on_focus_loss_enabled true
bool drag_and_drop_selection_enabled true
bool draw_control_chars false
bool editable true
bool emoji_menu_enabled true
bool expand_to_text_length false
bool flat false
Control.FocusMode focus_mode 2 (overrides Control)
ExpandMode icon_expand_mode 0
bool keep_editing_on_text_submit false
String language ""
int max_length 0
bool middle_mouse_paste_enabled true
Control.CursorShape mouse_default_cursor_shape 1 (overrides Control)
String placeholder_text ""
Texture2D right_icon
float right_icon_scale 1.0
bool secret false
String secret_character "•"
bool select_all_on_focus false
bool selecting_enabled true
bool shortcut_keys_enabled true
TextSystem.StructuredTextParser structured_text_bidi_override 0
Array structured_text_bidi_override_options []
String text ""
Control.TextDirection text_direction 0
bool virtual_keyboard_enabled true
bool virtual_keyboard_show_on_focus true
VirtualKeyboardType virtual_keyboard_type 0
Returns Method
void apply_ime()
void cancel_ime()
void clear()
void delete_char_at_caret()
void delete_text(from_column: int, to_column: int)
void deselect()
void edit(hide_focus: bool = false)
PopupMenu get_menu() const
int get_next_composite_character_column(column: int) const
int get_previous_composite_character_column(column: int) const
float get_scroll_offset() const
String get_selected_text()
int get_selection_from_column() const
int get_selection_to_column() const
bool has_ime_text() const
bool has_redo() const
bool has_selection() const
bool has_undo() const
void insert_text_at_caret(text: String)
bool is_editing() const
bool is_menu_visible() const
void menu_option(option: int)
void select(from: int = 0, to: int = -1)
void select_all()
void unedit()

editing_toggled

editing_toggled(toggled_on: bool)

Emitted when the LineEdit switches in or out of edit mode.

text_change_rejected

text_change_rejected(rejected_substring: String)

Emitted when appending text that overflows the max_length. The appended text is truncated to fit max_length, and the part that couldn’t fit is passed as the rejected_substring argument.

text_changed

text_changed(new_text: String)

Emitted when the text changes.

text_submitted

text_submitted(new_text: String)

Emitted when the user presses the ui_text_submit action (by default: Enter or Kp Enter) while the LineEdit has focus.

MenuItems

enum MenuItems

MENU_CUT = 0

Cuts (copies and clears) the selected text.

MENU_COPY = 1

Copies the selected text.

MENU_PASTE = 2

Pastes the clipboard text over the selected text (or at the caret’s position).

Non-printable escape characters are automatically stripped from the OS clipboard via String.strip_escapes().

MENU_CLEAR = 3

Erases the whole LineEdit text.

MENU_SELECT_ALL = 4

Selects the whole LineEdit text.

MENU_UNDO = 5

Undoes the previous action.

MENU_REDO = 6

Reverse the last undo action.

MENU_SUBMENU_TEXT_DIR = 7

ID of “Text Writing Direction” submenu.

MENU_DIR_INHERITED = 8

Sets text direction to inherited.

MENU_DIR_AUTO = 9

Sets text direction to automatic.

MENU_DIR_LTR = 10

Sets text direction to left-to-right.

MENU_DIR_RTL = 11

Sets text direction to right-to-left.

MENU_DISPLAY_UCC = 12

Toggles control character display.

MENU_SUBMENU_INSERT_UCC = 13

ID of “Insert Control Character” submenu.

MENU_INSERT_LRM = 14

Inserts left-to-right mark (LRM) character.

MENU_INSERT_RLM = 15

Inserts right-to-left mark (RLM) character.

MENU_INSERT_LRE = 16

Inserts start of left-to-right embedding (LRE) character.

MENU_INSERT_RLE = 17

Inserts start of right-to-left embedding (RLE) character.

MENU_INSERT_LRO = 18

Inserts start of left-to-right override (LRO) character.

MENU_INSERT_RLO = 19

Inserts start of right-to-left override (RLO) character.

MENU_INSERT_PDF = 20

Inserts pop direction formatting (PDF) character.

MENU_INSERT_ALM = 21

Inserts Arabic letter mark (ALM) character.

MENU_INSERT_LRI = 22

Inserts left-to-right isolate (LRI) character.

MENU_INSERT_RLI = 23

Inserts right-to-left isolate (RLI) character.

MENU_INSERT_FSI = 24

Inserts first strong isolate (FSI) character.

MENU_INSERT_PDI = 25

Inserts pop direction isolate (PDI) character.

MENU_INSERT_ZWJ = 26

Inserts zero width joiner (ZWJ) character.

MENU_INSERT_ZWNJ = 27

Inserts zero width non-joiner (ZWNJ) character.

MENU_INSERT_WJ = 28

Inserts word joiner (WJ) character.

MENU_INSERT_SHY = 29

Inserts soft hyphen (SHY) character.

MENU_EMOJI_AND_SYMBOL = 30

Opens system emoji and symbol picker.

MENU_MAX = 31

Represents the size of the MenuItems enum.

VirtualKeyboardType

enum VirtualKeyboardType

KEYBOARD_TYPE_DEFAULT = 0

Default text virtual keyboard.

KEYBOARD_TYPE_MULTILINE = 1

Multiline virtual keyboard.

KEYBOARD_TYPE_NUMBER = 2

Virtual number keypad, useful for PIN entry.

KEYBOARD_TYPE_NUMBER_DECIMAL = 3

Virtual number keypad, useful for entering fractional numbers.

KEYBOARD_TYPE_PHONE = 4

Virtual phone number keypad.

KEYBOARD_TYPE_EMAIL_ADDRESS = 5

Virtual keyboard with additional keys to assist with typing email addresses.

KEYBOARD_TYPE_PASSWORD = 6

Virtual keyboard for entering a password. On most platforms, this should disable autocomplete and autocapitalization.

Note: This is not supported on Web. Instead, this behaves identically to KEYBOARD_TYPE_DEFAULT.

KEYBOARD_TYPE_URL = 7

Virtual keyboard with additional keys to assist with typing URLs.

ExpandMode

enum ExpandMode

EXPAND_MODE_ORIGINAL_SIZE = 0

Use the original size for the right icon.

EXPAND_MODE_FIT_TO_TEXT = 1

Scale the right icon’s size to match the size of the text.

EXPAND_MODE_FIT_TO_LINE_EDIT = 2

Scale the right icon to fit the LineEdit.

caret_color

Color caret_color (color) = Color(0.95, 0.95, 0.95, 1)

clear_button_color

Color clear_button_color (color) = Color(0.875, 0.875, 0.875, 1)

clear_button_color_pressed

Color clear_button_color_pressed (color) = Color(1, 1, 1, 1)

font_color

Color font_color (color) = Color(0.875, 0.875, 0.875, 1)

font_outline_color

Color font_outline_color (color) = Color(0, 0, 0, 1)

font_placeholder_color

Color font_placeholder_color (color) = Color(0.875, 0.875, 0.875, 0.6)

font_selected_color

Color font_selected_color (color) = Color(1, 1, 1, 1)

font_uneditable_color

Color font_uneditable_color (color) = Color(0.875, 0.875, 0.875, 0.5)

selection_color

Color selection_color (color) = Color(0.5, 0.5, 0.5, 1)

caret_width

int caret_width (constant) = 1

minimum_character_width

int minimum_character_width (constant) = 4

outline_size

int outline_size (constant) = 0

font

Font font (font)

font_size

int font_size (font_size)

clear

Texture2D clear (icon)

caret_move_rejected_sound

AudioStream caret_move_rejected_sound (sound)

caret_moved_sound

AudioStream caret_moved_sound (sound)

focus_sound

AudioStream focus_sound (sound)

text_change_rejected_sound

AudioStream text_change_rejected_sound (sound)

text_changed_sound

AudioStream text_changed_sound (sound)

text_submitted_sound

AudioStream text_submitted_sound (sound)

focus

StyleBox focus (style)

normal

StyleBox normal (style)

read_only

StyleBox read_only (style)

alignment

HorizontalAlignment alignment = 0

The text’s horizontal alignment.

backspace_deletes_composite_character_enabled

bool backspace_deletes_composite_character_enabled = false

If true and caret_mid_grapheme is false, backspace deletes an entire composite character such as ❤️‍🩹, instead of deleting part of the composite character.

bool caret_blink = false

If true, makes the caret blink.

float caret_blink_interval = 0.65

The interval at which the caret blinks (in seconds).

caret_column

int caret_column = 0

The caret’s column position inside the LineEdit. When set, the text may scroll to accommodate it.

caret_force_displayed

bool caret_force_displayed = false

If true, the LineEdit will always show the caret, even if not editing or focus is lost.

caret_mid_grapheme

bool caret_mid_grapheme = false

Allow moving caret, selecting and removing the individual composite character components.

Note: Backspace is always removing individual composite character components.

clear_button_enabled

bool clear_button_enabled = false

If true, the LineEdit will show a clear button if text is not empty, which can be used to clear the text quickly.

context_menu_enabled

bool context_menu_enabled = true

If true, the context menu will appear when right-clicked.

deselect_on_focus_loss_enabled

bool deselect_on_focus_loss_enabled = true

If true, the selected text will be deselected when focus is lost.

drag_and_drop_selection_enabled

bool drag_and_drop_selection_enabled = true

If true, allow drag and drop of selected text.

draw_control_chars

bool draw_control_chars = false

If true, control characters are displayed.

editable

bool editable = true

If false, existing text cannot be modified and new text cannot be added.

emoji_menu_enabled

bool emoji_menu_enabled = true

If true, “Emoji and Symbols” menu is enabled.

expand_to_text_length

bool expand_to_text_length = false

If true, the LineEdit width will increase to stay longer than the text. It will not compress if the text is shortened.

flat

bool flat = false

If true, the LineEdit doesn’t display decoration.

icon_expand_mode

ExpandMode icon_expand_mode = 0

Define the scaling behavior of the right_icon and the clear button.

keep_editing_on_text_submit

bool keep_editing_on_text_submit = false

If true, the LineEdit will not exit edit mode when text is submitted by pressing ui_text_submit action (by default: Enter or Kp Enter).

language

String language = ""

Language code used for line-breaking and text shaping algorithms. If left empty, the current locale is used instead.

max_length

int max_length = 0

Maximum number of characters that can be entered inside the LineEdit. If 0, there is no limit.

When a limit is defined, characters that would exceed max_length are truncated. This happens both for existing text contents when setting the max length, or for new text inserted in the LineEdit, including pasting.

If any input text is truncated, the text_change_rejected signal is emitted with the truncated substring as a parameter:

Text = "Hello world";
MaxLength = 5;
// `Text` becomes "Hello".
MaxLength = 10;
Text += " goodbye";
// `Text` becomes "Hello good".
// `text_change_rejected` is emitted with "bye" as a parameter.

middle_mouse_paste_enabled

bool middle_mouse_paste_enabled = true

If false, using middle mouse button to paste clipboard will be disabled.

Note: This method is only implemented on Linux.

placeholder_text

String placeholder_text = ""

Text shown when the LineEdit is empty. It is not the LineEdit’s default value (see text).

right_icon

Texture2D right_icon

Sets the icon that will appear in the right end of the LineEdit if there’s no text, or always, if clear_button_enabled is set to false.

right_icon_scale

float right_icon_scale = 1.0

Scale ratio of the icon when icon_expand_mode is set to EXPAND_MODE_FIT_TO_LINE_EDIT.

secret

bool secret = false

If true, every character is replaced with the secret character (see secret_character).

secret_character

String secret_character = "•"

The character to use to mask secret input. Only a single character can be used as the secret character. If it is longer than one character, only the first one will be used. If it is empty, a space will be used instead.

select_all_on_focus

bool select_all_on_focus = false

If true, the LineEdit will select the whole text when it gains focus.

selecting_enabled

bool selecting_enabled = true

If false, it’s impossible to select the text using mouse nor keyboard.

shortcut_keys_enabled

bool shortcut_keys_enabled = true

If true, shortcut keys for context menu items are enabled, even if the context menu is disabled.

structured_text_bidi_override

TextSystem.StructuredTextParser structured_text_bidi_override = 0

Set BiDi algorithm override for the structured text.

structured_text_bidi_override_options

Array structured_text_bidi_override_options = []

Set additional options for BiDi override.

text

String text = ""

String value of the LineEdit.

Note: Changing text using this property won’t emit the text_changed signal.

text_direction

Control.TextDirection text_direction = 0

Base text writing direction.

virtual_keyboard_enabled

bool virtual_keyboard_enabled = true

If true, the native virtual keyboard is enabled on platforms that support it.

virtual_keyboard_show_on_focus

bool virtual_keyboard_show_on_focus = true

If true, the native virtual keyboard is shown on focus events on platforms that support it.

virtual_keyboard_type

VirtualKeyboardType virtual_keyboard_type = 0

Specifies the type of virtual keyboard to show.

apply_ime

void apply_ime()

Applies text from the Input Method Editor (IME) and closes the IME if it is open.

cancel_ime

void cancel_ime()

Closes the Input Method Editor (IME) if it is open. Any text in the IME will be lost.

clear

void clear()

Erases the LineEdit’s text.

delete_char_at_caret

void delete_char_at_caret()

Deletes one character at the caret’s current position (equivalent to pressing Delete).

delete_text

void delete_text(from_column: int, to_column: int)

Deletes a section of the text going from position from_column to to_column. Both parameters should be within the text’s length.

deselect

void deselect()

Clears the current selection.

edit

void edit(hide_focus: bool = false)

Allows entering edit mode whether the LineEdit is focused or not. If hide_focus is true, the focused state will not be shown (see Control.grab_focus()).

See also keep_editing_on_text_submit.

get_menu

PopupMenu get_menu() const

Returns the PopupMenu of this LineEdit. By default, this menu is displayed when right-clicking on the LineEdit.

You can add custom menu items or remove standard ones. Make sure your IDs don’t conflict with the standard ones (see MenuItems). For example:

public override void OnStart()
{
var menu = GetMenu();
// Remove all items after "Redo".
menu.ItemCount = menu.GetItemIndex(LineEdit.MenuItems.Redo) + 1;
// Add custom items.
menu.AddSeparator();
menu.AddItem("Insert Date", LineEdit.MenuItems.Max + 1);
// Add event handler.
menu.IdPressed += OnItemPressed;
}
public void OnItemPressed(int id)
{
if (id == LineEdit.MenuItems.Max + 1)
{
InsertTextAtCaret(Time.GetDateStringFromSystem());
}
}

Warning: This is a required internal node, removing and freeing it may cause a crash. If you wish to hide it or any of its children, use their Window.visible property.

get_next_composite_character_column

int get_next_composite_character_column(column: int) const

Returns the correct column at the end of a composite character like ❤️‍🩹 (mending heart; Unicode: U+2764 U+FE0F U+200D U+1FA79) which is comprised of more than one Unicode code point, if the caret is at the start of the composite character. Also returns the correct column with the caret at mid grapheme and for non-composite characters.

Note: To check at caret location use get_next_composite_character_column(get_caret_column())

get_previous_composite_character_column

int get_previous_composite_character_column(column: int) const

Returns the correct column at the start of a composite character like ❤️‍🩹 (mending heart; Unicode: U+2764 U+FE0F U+200D U+1FA79) which is comprised of more than one Unicode code point, if the caret is at the end of the composite character. Also returns the correct column with the caret at mid grapheme and for non-composite characters.

Note: To check at caret location use get_previous_composite_character_column(get_caret_column())

get_scroll_offset

float get_scroll_offset() const

Returns the scroll offset due to caret_column, as a number of characters.

get_selected_text

String get_selected_text()

Returns the text inside the selection.

get_selection_from_column

int get_selection_from_column() const

Returns the selection begin column.

get_selection_to_column

int get_selection_to_column() const

Returns the selection end column.

has_ime_text

bool has_ime_text() const

Returns true if the user has text in the Input Method Editor (IME).

has_redo

bool has_redo() const

Returns true if a “redo” action is available.

has_selection

bool has_selection() const

Returns true if the user has selected text.

has_undo

bool has_undo() const

Returns true if an “undo” action is available.

insert_text_at_caret

void insert_text_at_caret(text: String)

Inserts text at the caret. If the resulting value is longer than max_length, nothing happens.

is_editing

bool is_editing() const

Returns whether the LineEdit is being edited.

is_menu_visible

bool is_menu_visible() const

Returns whether the menu is visible. Use this instead of get_menu().visible to improve performance (so the creation of the menu is avoided).

menu_option

void menu_option(option: int)

Executes a given action as defined in the MenuItems enum.

select

void select(from: int = 0, to: int = -1)

Selects characters inside LineEdit between from and to. By default, from is at the beginning and to at the end.

Text = "Welcome";
Select(); // Will select "Welcome".
Select(4); // Will select "ome".
Select(2, 5); // Will select "lco".

select_all

void select_all()

Selects the whole String.

unedit

void unedit()

Allows exiting edit mode while preserving focus.