aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaulb232016-03-31 20:49:30 +0100
committerRémi Verschelde2016-04-06 18:45:56 +0200
commit22ef9673dd78caba3f0eebb2c1e0ddb4d7dfca41 (patch)
tree52cad810a88f753558024ff247e53bbb6e3cb5b4
parent5b1aa3a5cdd893847a6a74b24a9a8815d5ae13c6 (diff)
downloadgodot-22ef9673dd78caba3f0eebb2c1e0ddb4d7dfca41.tar.gz
godot-22ef9673dd78caba3f0eebb2c1e0ddb4d7dfca41.tar.zst
godot-22ef9673dd78caba3f0eebb2c1e0ddb4d7dfca41.zip
Added insert mode to text editor
(cherry picked from commit 2b57cb94da8bfad1f32a89437f4978301da92e10)
-rw-r--r--scene/gui/text_edit.cpp45
-rw-r--r--scene/gui/text_edit.h4
2 files changed, 46 insertions, 3 deletions
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index 99efce42c..f7dbae9de 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -908,7 +908,12 @@ void TextEdit::_notification(int p_what) {
if (cursor.column==j && cursor.line==line) {
cursor_pos = Point2i( char_ofs+char_margin, ofs_y );
- VisualServer::get_singleton()->canvas_item_add_rect(ci,Rect2(cursor_pos, Size2i(1,get_row_height())),cache.font_color);
+ if (insert_mode) {
+ cursor_pos.y += get_row_height();
+ VisualServer::get_singleton()->canvas_item_add_rect(ci,Rect2(cursor_pos, Size2i(char_w,1)),cache.font_color);
+ } else {
+ VisualServer::get_singleton()->canvas_item_add_rect(ci,Rect2(cursor_pos, Size2i(1,get_row_height())),cache.font_color);
+ }
}
@@ -919,8 +924,13 @@ void TextEdit::_notification(int p_what) {
if (cursor.column==str.length() && cursor.line==line && (char_ofs+char_margin)>=xmargin_beg) {
cursor_pos=Point2i( char_ofs+char_margin, ofs_y );
- VisualServer::get_singleton()->canvas_item_add_rect(ci,Rect2(cursor_pos, Size2i(1,get_row_height())),cache.font_color);
-
+ if (insert_mode) {
+ cursor_pos.y += get_row_height();
+ int char_w = cache.font->get_char_size(' ').width;
+ VisualServer::get_singleton()->canvas_item_add_rect(ci,Rect2(cursor_pos, Size2i(char_w,1)),cache.font_color);
+ } else {
+ VisualServer::get_singleton()->canvas_item_add_rect(ci,Rect2(cursor_pos, Size2i(1,get_row_height())),cache.font_color);
+ }
}
}
@@ -2332,6 +2342,12 @@ void TextEdit::_input_event(const InputEvent& p_input_event) {
}
}
*/
+ if (k.scancode==KEY_INSERT) {
+ set_insert_mode(!insert_mode);
+ accept_event();
+ return;
+ }
+
if (!scancode_handled && !k.mod.command) { //for german kbds
if (k.unicode>=32) {
@@ -2339,6 +2355,16 @@ void TextEdit::_input_event(const InputEvent& p_input_event) {
if (readonly)
break;
+ // remove the old character if in insert mode
+ if (insert_mode) {
+ _begin_compex_operation();
+
+ // make sure we don't try and remove empty space
+ if (cursor.column < get_line(cursor.line).length()) {
+ _remove_text(cursor.line, cursor.column, cursor.line, cursor.column + 1);
+ }
+ }
+
const CharType chr[2] = {(CharType)k.unicode, 0};
if (completion_hint!="" && k.unicode==')') {
@@ -2350,6 +2376,9 @@ void TextEdit::_input_event(const InputEvent& p_input_event) {
_insert_text_at_cursor(chr);
}
+ if (insert_mode) {
+ _end_compex_operation();
+ }
accept_event();
} else {
@@ -3593,6 +3622,15 @@ bool TextEdit::is_drawing_tabs() const{
return draw_tabs;
}
+void TextEdit::set_insert_mode(bool p_enabled) {
+ insert_mode = p_enabled;
+ update();
+}
+
+bool TextEdit::is_insert_mode() const {
+ return insert_mode;
+}
+
uint32_t TextEdit::get_version() const {
return current_op.version;
}
@@ -4085,6 +4123,7 @@ TextEdit::TextEdit() {
auto_brace_completion_enabled=false;
brace_matching_enabled=false;
auto_indent=false;
+ insert_mode = false;
}
TextEdit::~TextEdit()
diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h
index 39ed367a1..22071640a 100644
--- a/scene/gui/text_edit.h
+++ b/scene/gui/text_edit.h
@@ -221,6 +221,7 @@ class TextEdit : public Control {
bool brace_matching_enabled;
bool auto_indent;
bool cut_copy_line;
+ bool insert_mode;
uint64_t last_dblclk;
@@ -390,6 +391,9 @@ public:
void set_draw_tabs(bool p_draw);
bool is_drawing_tabs() const;
+ void set_insert_mode(bool p_enabled);
+ bool is_insert_mode() const;
+
void add_keyword_color(const String& p_keyword,const Color& p_color);
void add_color_region(const String& p_begin_key=String(),const String& p_end_key=String(),const Color &p_color=Color(),bool p_line_only=false);
void set_symbol_color(const Color& p_color);