Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.x] Add selection getter methods to LineEdit #60176

Merged
merged 1 commit into from
Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions doc/classes/LineEdit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,24 @@
Returns the scroll offset due to [member caret_position], as a number of characters.
</description>
</method>
<method name="get_selection_from_column" qualifiers="const">
<return type="int" />
<description>
Returns the selection begin column.
</description>
</method>
<method name="get_selection_to_column" qualifiers="const">
<return type="int" />
<description>
Returns the selection end column.
</description>
</method>
<method name="has_selection" qualifiers="const">
<return type="bool" />
<description>
Returns [code]true[/code] if the user has selected text.
</description>
</method>
<method name="menu_option">
<return type="void" />
<argument index="0" name="option" type="int" />
Expand Down
17 changes: 17 additions & 0 deletions scene/gui/line_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1584,6 +1584,20 @@ void LineEdit::deselect() {
update();
}

bool LineEdit::has_selection() const {
return selection.enabled;
}

int LineEdit::get_selection_from_column() const {
ERR_FAIL_COND_V(!selection.enabled, -1);
return selection.begin;
}

int LineEdit::get_selection_to_column() const {
ERR_FAIL_COND_V(!selection.enabled, -1);
return selection.end;
}

void LineEdit::selection_delete() {
if (selection.enabled) {
delete_text(selection.begin, selection.end);
Expand Down Expand Up @@ -1956,6 +1970,9 @@ void LineEdit::_bind_methods() {
ClassDB::bind_method(D_METHOD("select", "from", "to"), &LineEdit::select, DEFVAL(0), DEFVAL(-1));
ClassDB::bind_method(D_METHOD("select_all"), &LineEdit::select_all);
ClassDB::bind_method(D_METHOD("deselect"), &LineEdit::deselect);
ClassDB::bind_method(D_METHOD("has_selection"), &LineEdit::has_selection);
ClassDB::bind_method(D_METHOD("get_selection_from_column"), &LineEdit::get_selection_from_column);
ClassDB::bind_method(D_METHOD("get_selection_to_column"), &LineEdit::get_selection_to_column);
ClassDB::bind_method(D_METHOD("set_text", "text"), &LineEdit::set_text);
ClassDB::bind_method(D_METHOD("get_text"), &LineEdit::get_text);
ClassDB::bind_method(D_METHOD("set_placeholder", "text"), &LineEdit::set_placeholder);
Expand Down
3 changes: 3 additions & 0 deletions scene/gui/line_edit.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ class LineEdit : public Control {
void select_all();
void selection_delete();
void deselect();
bool has_selection() const;
int get_selection_from_column() const;
int get_selection_to_column() const;

void delete_char();
void delete_text(int p_from_column, int p_to_column);
Expand Down