Added insert mode to text editor

(cherry picked from commit 2b57cb94da)
This commit is contained in:
Paulb23 2016-03-31 20:49:30 +01:00 committed by Rémi Verschelde
parent 5b1aa3a5cd
commit 22ef9673dd
2 changed files with 46 additions and 3 deletions

View File

@ -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 );
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 );
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()

View File

@ -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);