diff options
author | Paulb23 <p_batty@hotmail.co.uk> | 2016-03-31 20:49:30 +0100 |
---|---|---|
committer | Paulb23 <p_batty@hotmail.co.uk> | 2016-04-01 13:48:38 +0100 |
commit | 2b57cb94da8bfad1f32a89437f4978301da92e10 (patch) | |
tree | 45d3f83375c4ce25a5a2cac4434fe4de9f87ca1a /scene | |
parent | 8708a284f7b5390a48ea2fd95848f60cc40d0bf0 (diff) |
Added insert mode to text editor
Diffstat (limited to 'scene')
-rw-r--r-- | scene/gui/text_edit.cpp | 45 | ||||
-rw-r--r-- | scene/gui/text_edit.h | 4 |
2 files changed, 46 insertions, 3 deletions
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index f5e1c82300..ff9adc6bed 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -890,7 +890,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); + } } @@ -901,8 +906,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); + } } } @@ -2335,6 +2345,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) { @@ -2342,6 +2358,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==')') { @@ -2353,6 +2379,9 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { _insert_text_at_cursor(chr); } + if (insert_mode) { + _end_compex_operation(); + } accept_event(); } else { @@ -3595,6 +3624,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; } @@ -4087,6 +4125,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 e7e6760379..a268cca90f 100644 --- a/scene/gui/text_edit.h +++ b/scene/gui/text_edit.h @@ -220,6 +220,7 @@ class TextEdit : public Control { bool brace_matching_enabled; bool auto_indent; bool cut_copy_line; + bool insert_mode; uint64_t last_dblclk; @@ -389,6 +390,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); |