summaryrefslogtreecommitdiff
path: root/scene/gui
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui')
-rw-r--r--scene/gui/text_edit.cpp22
-rw-r--r--scene/gui/text_edit.h2
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();