summaryrefslogtreecommitdiff
path: root/scene/gui/text_edit.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui/text_edit.cpp')
-rw-r--r--scene/gui/text_edit.cpp103
1 files changed, 58 insertions, 45 deletions
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index 49d7527786..5e18da32aa 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -417,8 +417,22 @@ void TextEdit::_notification(int p_what) {
_update_caches();
} break;
+ case MainLoop::NOTIFICATION_WM_FOCUS_IN: {
+ window_has_focus = true;
+ draw_caret = true;
+ update();
+ } break;
+ case MainLoop::NOTIFICATION_WM_FOCUS_OUT: {
+ window_has_focus = false;
+ draw_caret = false;
+ update();
+ } break;
case NOTIFICATION_DRAW: {
+ if ((!has_focus() && !menu->has_focus()) || !window_has_focus) {
+ draw_caret = false;
+ }
+
if (draw_breakpoint_gutter) {
breakpoint_gutter_width = (get_row_height() * 55) / 100;
cache.breakpoint_gutter_width = breakpoint_gutter_width;
@@ -1195,6 +1209,9 @@ void TextEdit::_notification(int p_what) {
} break;
case NOTIFICATION_FOCUS_ENTER: {
+ if (!caret_blink_enabled) {
+ draw_caret = true;
+ }
if (OS::get_singleton()->has_virtual_keyboard())
OS::get_singleton()->show_virtual_keyboard(get_text(),get_global_rect());
@@ -1452,10 +1469,10 @@ void TextEdit::_input_event(const InputEvent& p_input_event) {
}
if (mb.pressed) {
- if (mb.button_index==BUTTON_WHEEL_UP) {
+ if (mb.button_index==BUTTON_WHEEL_UP && !mb.mod.command) {
v_scroll->set_val( v_scroll->get_val() -3 );
}
- if (mb.button_index==BUTTON_WHEEL_DOWN) {
+ if (mb.button_index==BUTTON_WHEEL_DOWN && !mb.mod.command) {
v_scroll->set_val( v_scroll->get_val() +3 );
}
if (mb.button_index==BUTTON_WHEEL_LEFT) {
@@ -3837,8 +3854,14 @@ void TextEdit::undo() {
}
}
- cursor_set_line(undo_stack_pos->get().from_line);
- cursor_set_column(undo_stack_pos->get().from_column);
+ if (undo_stack_pos->get().type == TextOperation::TYPE_REMOVE) {
+ cursor_set_line(undo_stack_pos->get().to_line);
+ cursor_set_column(undo_stack_pos->get().to_column);
+ _cancel_code_hint();
+ } else {
+ cursor_set_line(undo_stack_pos->get().from_line);
+ cursor_set_column(undo_stack_pos->get().from_column);
+ }
update();
}
@@ -3981,28 +4004,19 @@ void TextEdit::set_completion(bool p_enabled,const Vector<String>& p_prefixes) {
void TextEdit::_confirm_completion() {
- String remaining=completion_current.substr(completion_base.length(),completion_current.length()-completion_base.length());
- String l = text[cursor.line];
- bool same=true;
- //if what is going to be inserted is the same as what it is, don't change it
- for(int i=0;i<remaining.length();i++) {
- int c=i+cursor.column;
- if (c>=l.length() || l[c]!=remaining[i]) {
- same=false;
- break;
- }
- }
+ begin_complex_operation();
- if (same)
- cursor_set_column(cursor.column+remaining.length());
- else {
- insert_text_at_cursor(remaining);
- if (remaining.ends_with("(") && auto_brace_completion_enabled) {
- insert_text_at_cursor(")");
- cursor.column--;
- }
+ _remove_text(cursor.line, cursor.column - completion_base.length(), cursor.line, cursor.column);
+ cursor_set_column(cursor.column - completion_base.length(), false);
+ insert_text_at_cursor(completion_current);
+
+ if (completion_current.ends_with("(") && auto_brace_completion_enabled) {
+ insert_text_at_cursor(")");
+ cursor.column--;
}
+ end_complex_operation();
+
_cancel_completion();
}
@@ -4105,30 +4119,29 @@ void TextEdit::_update_completion_candidates() {
completion_index=0;
completion_base=s;
int ci_match=0;
+ Vector<float> sim_cache;
for(int i=0;i<completion_strings.size();i++) {
- if (completion_strings[i].begins_with(s)) {
+ if (s.is_subsequence_ofi(completion_strings[i])) {
// don't remove duplicates if no input is provided
- if (completion_options.find(completion_strings[i]) != -1 && s != "") {
+ if (s != "" && completion_options.find(completion_strings[i]) != -1) {
continue;
}
- completion_options.push_back(completion_strings[i]);
- int m=0;
- int max=MIN(completion_current.length(),completion_strings[i].length());
- if (max<ci_match)
- continue;
- for(int j=0;j<max;j++) {
-
- if (j>=completion_strings[i].length())
- break;
- if (completion_current[j]!=completion_strings[i][j])
- break;
- m++;
- }
- if (m>ci_match) {
- ci_match=m;
- completion_index=completion_options.size()-1;
+ // Calculate the similarity to keep completions in good order
+ float similarity = s.similarity(completion_strings[i]);
+ int comp_size = completion_options.size();
+ if (comp_size == 0) {
+ completion_options.push_back(completion_strings[i]);
+ sim_cache.push_back(similarity);
+ } else {
+ float comp_sim;
+ int pos = 0;
+ do {
+ comp_sim = sim_cache[pos++];
+ } while(pos < comp_size && similarity <= comp_sim);
+ pos--; // Pos will be off by one
+ completion_options.insert(pos, completion_strings[i]);
+ sim_cache.insert(pos, similarity);
}
-
}
}
@@ -4141,7 +4154,8 @@ void TextEdit::_update_completion_candidates() {
}
- completion_current=completion_options[completion_index];
+ // The top of the list is the best match
+ completion_current=completion_options[0];
#if 0 // even there's only one option, user still get the chance to choose using it or not
if (completion_options.size()==1) {
@@ -4153,8 +4167,6 @@ void TextEdit::_update_completion_candidates() {
}
#endif
- if (completion_options.size()==1 && s==completion_options[0])
- _cancel_completion();
completion_enabled=true;
}
@@ -4518,6 +4530,7 @@ TextEdit::TextEdit() {
brace_matching_enabled=false;
auto_indent=false;
insert_mode = false;
+ window_has_focus=true;
menu = memnew( PopupMenu );
add_child(menu);