Skip to content

Commit

Permalink
Merge pull request #33202 from nekomatata/text-edit-search-usability
Browse files Browse the repository at this point in the history
Improved TextEdit search usability & documentation
  • Loading branch information
akien-mga authored Nov 1, 2019
2 parents b473787 + d29c8ab commit a49c8d4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
16 changes: 15 additions & 1 deletion doc/classes/TextEdit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,15 @@
<argument index="3" name="from_column" type="int">
</argument>
<description>
Perform a search inside the text. Search flags can be specified in the[code]SEARCH_*[/code] enum.
Perform a search inside the text. Search flags can be specified in the [code]SEARCH_*[/code] enum.
Returns an empty [code]PoolIntArray[/code] if no result was found. Otherwise, the result line and column can be accessed at indices specified in the [code]SEARCH_RESULT_*[/code] enum, e.g:
[codeblock]
var result = search(key, flags, line, column)
if result.size() > 0:
# result found
var res_line = result[TextEdit.SEARCH_RESULT_LINE]
var res_column = result[TextEdit.SEARCH_RESULT_COLUMN]
[/codeblock]
</description>
</method>
<method name="select">
Expand Down Expand Up @@ -504,6 +512,12 @@
<constant name="SEARCH_BACKWARDS" value="4" enum="SearchFlags">
Search from end to beginning.
</constant>
<constant name="SEARCH_RESULT_COLUMN" value="0" enum="SearchResult">
Used to access the result column from [member search].
</constant>
<constant name="SEARCH_RESULT_LINE" value="1" enum="SearchResult">
Used to access the result line from [member search].
</constant>
<constant name="MENU_CUT" value="0" enum="MenuItems">
Cuts (Copies and clears) the selected text.
</constant>
Expand Down
9 changes: 6 additions & 3 deletions scene/gui/text_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5443,11 +5443,11 @@ int TextEdit::_get_column_pos_of_word(const String &p_key, const String &p_searc
PoolVector<int> TextEdit::_search_bind(const String &p_key, uint32_t p_search_flags, int p_from_line, int p_from_column) const {

int col, line;
if (search(p_key, p_search_flags, p_from_line, p_from_column, col, line)) {
if (search(p_key, p_search_flags, p_from_line, p_from_column, line, col)) {
PoolVector<int> result;
result.resize(2);
result.set(0, line);
result.set(1, col);
result.set(SEARCH_RESULT_COLUMN, col);
result.set(SEARCH_RESULT_LINE, line);
return result;

} else {
Expand Down Expand Up @@ -6960,6 +6960,9 @@ void TextEdit::_bind_methods() {
BIND_ENUM_CONSTANT(SEARCH_WHOLE_WORDS);
BIND_ENUM_CONSTANT(SEARCH_BACKWARDS);

BIND_ENUM_CONSTANT(SEARCH_RESULT_COLUMN);
BIND_ENUM_CONSTANT(SEARCH_RESULT_LINE);

/*
ClassDB::bind_method(D_METHOD("delete_char"),&TextEdit::delete_char);
ClassDB::bind_method(D_METHOD("delete_line"),&TextEdit::delete_line);
Expand Down
7 changes: 6 additions & 1 deletion scene/gui/text_edit.h
Original file line number Diff line number Diff line change
Expand Up @@ -504,12 +504,16 @@ class TextEdit : public Control {
};

enum SearchFlags {

SEARCH_MATCH_CASE = 1,
SEARCH_WHOLE_WORDS = 2,
SEARCH_BACKWARDS = 4
};

enum SearchResult {
SEARCH_RESULT_COLUMN,
SEARCH_RESULT_LINE,
};

virtual CursorShape get_cursor_shape(const Point2 &p_pos = Point2i()) const;

void _get_mouse_pos(const Point2i &p_mouse, int &r_row, int &r_col) const;
Expand Down Expand Up @@ -768,6 +772,7 @@ class TextEdit : public Control {

VARIANT_ENUM_CAST(TextEdit::MenuItems);
VARIANT_ENUM_CAST(TextEdit::SearchFlags);
VARIANT_ENUM_CAST(TextEdit::SearchResult);

class SyntaxHighlighter {
protected:
Expand Down

0 comments on commit a49c8d4

Please sign in to comment.