Merge pull request #4193 from Paulb23/text_edit_insert_mode

Added insert mode to text editor
This commit is contained in:
Rémi Verschelde 2016-04-02 20:25:24 +02:00
commit 48f057ea81
2 changed files with 46 additions and 3 deletions

View File

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

View File

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