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.cpp37
1 files changed, 30 insertions, 7 deletions
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index 68529ae255..a5de50af99 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -215,8 +215,8 @@ void TextEdit::Text::_update_line_cache(int p_line) const {
const Map<int, TextEdit::Text::ColorRegionInfo> &TextEdit::Text::get_color_region_info(int p_line) {
- Map<int, ColorRegionInfo> *cri = NULL;
- ERR_FAIL_INDEX_V(p_line, text.size(), *cri); //enjoy your crash
+ static Map<int, ColorRegionInfo> cri;
+ ERR_FAIL_INDEX_V(p_line, text.size(), cri);
if (text[p_line].width_cache == -1) {
_update_line_cache(p_line);
@@ -2115,14 +2115,14 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
//keep indentation
int space_count = 0;
for (int i = 0; i < text[cursor.line].length(); i++) {
- if (text[cursor.line][i] == '\t') {
+ if (text[cursor.line][i] == '\t' && cursor.column > 0) {
if (indent_using_spaces) {
ins += space_indent;
} else {
ins += "\t";
}
space_count = 0;
- } else if (text[cursor.line][i] == ' ') {
+ } else if (text[cursor.line][i] == ' ' && cursor.column > 0) {
space_count++;
if (space_count == indent_size) {
@@ -2880,6 +2880,8 @@ void TextEdit::_post_shift_selection() {
}
void TextEdit::_scroll_lines_up() {
+ scrolling = false;
+
// adjust the vertical scroll
if (get_v_scroll() > 0) {
set_v_scroll(get_v_scroll() - 1);
@@ -2892,6 +2894,8 @@ void TextEdit::_scroll_lines_up() {
}
void TextEdit::_scroll_lines_down() {
+ scrolling = false;
+
// calculate the maximum vertical scroll position
int max_v_scroll = get_line_count() - 1;
if (!scroll_past_end_of_file_enabled) {
@@ -3156,6 +3160,7 @@ int TextEdit::get_visible_rows() const {
return total;
}
void TextEdit::adjust_viewport_to_cursor() {
+ scrolling = false;
if (cursor.line_ofs > cursor.line)
cursor.line_ofs = cursor.line;
@@ -3195,6 +3200,7 @@ void TextEdit::adjust_viewport_to_cursor() {
}
void TextEdit::center_viewport_to_cursor() {
+ scrolling = false;
if (cursor.line_ofs > cursor.line)
cursor.line_ofs = cursor.line;
@@ -3313,6 +3319,10 @@ bool TextEdit::cursor_is_block_mode() const {
return block_caret;
}
+void TextEdit::_v_scroll_input() {
+ scrolling = false;
+}
+
void TextEdit::_scroll_moved(double p_to_val) {
if (updating_scrolls)
@@ -4309,6 +4319,7 @@ void TextEdit::_cancel_completion() {
return;
completion_active = false;
+ completion_forced = false;
update();
}
@@ -4376,13 +4387,19 @@ void TextEdit::_update_completion_candidates() {
}
}
- if (cursor.column > 0 && l[cursor.column - 1] == '(' && !pre_keyword && !completion_strings[0].begins_with("\"")) {
+ if (cursor.column > 0 && l[cursor.column - 1] == '(' && !pre_keyword && !completion_forced) {
cancel = true;
}
update();
- if (cancel || (!pre_keyword && s == "" && (cofs == 0 || !completion_prefixes.has(String::chr(l[cofs - 1]))))) {
+ bool prev_is_prefix = false;
+ if (cofs > 0 && completion_prefixes.has(String::chr(l[cofs - 1])))
+ prev_is_prefix = true;
+ if (cofs > 1 && l[cofs - 1] == ' ' && completion_prefixes.has(String::chr(l[cofs - 2]))) //check with one space before prefix, to allow indent
+ prev_is_prefix = true;
+
+ if (cancel || (!pre_keyword && s == "" && (cofs == 0 || !prev_is_prefix))) {
//none to complete, cancel
_cancel_completion();
return;
@@ -4471,6 +4488,8 @@ void TextEdit::query_code_comple() {
if (ofs > 0 && (inquote || _is_completable(l[ofs - 1]) || completion_prefixes.has(String::chr(l[ofs - 1]))))
emit_signal("request_completion");
+ else if (ofs > 1 && l[ofs - 1] == ' ' && completion_prefixes.has(String::chr(l[ofs - 2]))) //make it work with a space too, it's good enough
+ emit_signal("request_completion");
}
void TextEdit::set_code_hint(const String &p_hint) {
@@ -4482,12 +4501,13 @@ void TextEdit::set_code_hint(const String &p_hint) {
update();
}
-void TextEdit::code_complete(const Vector<String> &p_strings) {
+void TextEdit::code_complete(const Vector<String> &p_strings, bool p_forced) {
VisualServer::get_singleton()->canvas_item_set_z(get_canvas_item(), 1);
raised_from_completion = true;
completion_strings = p_strings;
completion_active = true;
+ completion_forced = p_forced;
completion_current = "";
completion_index = 0;
_update_completion_candidates();
@@ -4706,6 +4726,7 @@ void TextEdit::_bind_methods() {
ClassDB::bind_method(D_METHOD("_push_current_op"), &TextEdit::_push_current_op);
ClassDB::bind_method(D_METHOD("_click_selection_held"), &TextEdit::_click_selection_held);
ClassDB::bind_method(D_METHOD("_toggle_draw_caret"), &TextEdit::_toggle_draw_caret);
+ ClassDB::bind_method(D_METHOD("_v_scroll_input"), &TextEdit::_v_scroll_input);
BIND_ENUM_CONSTANT(SEARCH_MATCH_CASE);
BIND_ENUM_CONSTANT(SEARCH_WHOLE_WORDS);
@@ -4843,6 +4864,8 @@ TextEdit::TextEdit() {
h_scroll->connect("value_changed", this, "_scroll_moved");
v_scroll->connect("value_changed", this, "_scroll_moved");
+ v_scroll->connect("scrolling", this, "_v_scroll_input");
+
cursor_changed_dirty = false;
text_changed_dirty = false;