From 212b8b2a0348eed9c7f2dd593fb103dc5d4af9d3 Mon Sep 17 00:00:00 2001 From: marynate Date: Tue, 6 May 2014 17:36:39 +0800 Subject: [PATCH] Add get_word_under_cursor() method to TextEdit --- scene/gui/text_edit.cpp | 22 ++++++++++++++++++++++ scene/gui/text_edit.h | 2 ++ 2 files changed, 24 insertions(+) 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 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();