TextEdit search returns a dictionary instead of Vector

Easier to use than accessing elements in a Vector using indices given by an enum.
Breaks compatibility on existing scripts using this functionality.
This commit is contained in:
PouleyKetchoupp 2020-05-16 23:23:46 +02:00
parent 163687d17a
commit 242b94af1a
3 changed files with 11 additions and 27 deletions

View file

@ -299,7 +299,7 @@
</description>
</method>
<method name="search" qualifiers="const">
<return type="PackedInt32Array">
<return type="Dictionary">
</return>
<argument index="0" name="key" type="String">
</argument>
@ -311,13 +311,13 @@
</argument>
<description>
Perform a search inside the text. Search flags can be specified in the [enum SearchFlags] enum.
Returns an empty [code]PackedInt32Array[/code] if no result was found. Otherwise, the result line and column can be accessed at indices specified in the [enum SearchResult] enum, e.g:
Returns an empty [code]Dictionary[/code] if no result was found. Otherwise, returns a [code]Dictionary[/code] containing [code]line[/code] and [code]column[/code] entries, e.g:
[codeblock]
var result = search(key, flags, line, column)
if result.size() &gt; 0:
if !result.empty():
# Result found.
var res_line = result[TextEdit.SEARCH_RESULT_LINE]
var res_column = result[TextEdit.SEARCH_RESULT_COLUMN]
var line_number = result.line
var column_number = result.column
[/codeblock]
</description>
</method>
@ -536,12 +536,6 @@
<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 [method search].
</constant>
<constant name="SEARCH_RESULT_LINE" value="1" enum="SearchResult">
Used to access the result line from [method search].
</constant>
<constant name="MENU_CUT" value="0" enum="MenuItems">
Cuts (copies and clears) the selected text.
</constant>

View file

@ -5447,17 +5447,16 @@ int TextEdit::_get_column_pos_of_word(const String &p_key, const String &p_searc
return col;
}
Vector<int> TextEdit::_search_bind(const String &p_key, uint32_t p_search_flags, int p_from_line, int p_from_column) const {
Dictionary 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, line, col)) {
Vector<int> result;
result.resize(2);
result.set(SEARCH_RESULT_COLUMN, col);
result.set(SEARCH_RESULT_LINE, line);
Dictionary result;
result["line"] = line;
result["column"] = col;
return result;
} else {
return Vector<int>();
return Dictionary();
}
}
@ -6980,9 +6979,6 @@ 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);

View file

@ -508,7 +508,7 @@ private:
int _get_column_pos_of_word(const String &p_key, const String &p_search, uint32_t p_search_flags, int p_from_column);
Vector<int> _search_bind(const String &p_key, uint32_t p_search_flags, int p_from_line, int p_from_column) const;
Dictionary _search_bind(const String &p_key, uint32_t p_search_flags, int p_from_line, int p_from_column) const;
PopupMenu *menu;
@ -561,11 +561,6 @@ public:
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;
@ -826,7 +821,6 @@ public:
VARIANT_ENUM_CAST(TextEdit::MenuItems);
VARIANT_ENUM_CAST(TextEdit::SearchFlags);
VARIANT_ENUM_CAST(TextEdit::SearchResult);
class SyntaxHighlighter {
protected: