diff options
author | marynate <mary.w.nate@gmail.com> | 2014-05-06 17:36:39 +0800 |
---|---|---|
committer | marynate <mary.w.nate@gmail.com> | 2014-05-06 19:21:21 +0800 |
commit | 212b8b2a0348eed9c7f2dd593fb103dc5d4af9d3 (patch) | |
tree | fc81dbfa439324ca6c6ac1ec05ebcf06691b7bc6 | |
parent | 145b8c5e6fb755a2454312dc6f49ca50ff5175b2 (diff) |
Add get_word_under_cursor() method to TextEdit
-rw-r--r-- | scene/gui/text_edit.cpp | 22 | ||||
-rw-r--r-- | scene/gui/text_edit.h | 2 |
2 files changed, 24 insertions, 0 deletions
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 87900306d4..bd15e14ccd 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -2485,6 +2485,27 @@ String TextEdit::get_selection_text() const { } +String TextEdit::get_word_under_cursor() const { + + int prev_cc = cursor.column; + while(prev_cc >0) { + bool is_char = _is_text_char(text[cursor.line][prev_cc-1]); + if (!is_char) + break; + --prev_cc; + } + + int next_cc = cursor.column; + while(next_cc<text[cursor.line].length()) { + bool is_char = _is_text_char(text[cursor.line][next_cc]); + if(!is_char) + break; + ++ next_cc; + } + if (prev_cc == cursor.column || next_cc == cursor.column) + return ""; + return text[cursor.line].substr(prev_cc, next_cc-prev_cc); +} DVector<int> TextEdit::_search_bind(const String &p_key,uint32_t p_search_flags, int p_from_line,int p_from_column) const { @@ -3037,6 +3058,7 @@ void TextEdit::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_selection_to_line"),&TextEdit::get_selection_to_line); ObjectTypeDB::bind_method(_MD("get_selection_to_column"),&TextEdit::get_selection_to_column); ObjectTypeDB::bind_method(_MD("get_selection_text"),&TextEdit::get_selection_text); + ObjectTypeDB::bind_method(_MD("get_word_under_cursor"),&TextEdit::get_word_under_cursor); ObjectTypeDB::bind_method(_MD("search","flags","from_line","from_column","to_line","to_column"),&TextEdit::_search_bind); ObjectTypeDB::bind_method(_MD("undo"),&TextEdit::undo); diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h index 58d62dea48..7700bfd4d3 100644 --- a/scene/gui/text_edit.h +++ b/scene/gui/text_edit.h @@ -341,6 +341,8 @@ public: int get_selection_to_column() const; String get_selection_text() const; + String get_word_under_cursor() const; + bool search(const String &p_key,uint32_t p_search_flags, int p_from_line, int p_from_column,int &r_line,int &r_column) const; void undo(); |