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.cpp79
1 files changed, 68 insertions, 11 deletions
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index 55ac324af3..e8454e021f 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -455,7 +455,7 @@ void TextEdit::_update_selection_mode_word() {
end += 1;
}
- // inital selection
+ // initial selection
if (!selection.active) {
select(row, beg, row, end);
selection.selecting_column = beg;
@@ -888,9 +888,9 @@ void TextEdit::_notification(int p_what) {
VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg + ofs_x, ofs_y, char_w, get_row_height()), cache.selection_color);
}
} else {
- // if it has text, then draw current line marker in the margin, as line number ect will draw over it, draw the rest of line marker later.
+ // if it has text, then draw current line marker in the margin, as line number etc will draw over it, draw the rest of line marker later.
if (line == cursor.line && highlight_current_line) {
- VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(0, ofs_y, xmargin_beg, get_row_height()), cache.current_line_color);
+ VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(0, ofs_y, xmargin_beg + ofs_x, get_row_height()), cache.current_line_color);
}
}
@@ -937,7 +937,7 @@ void TextEdit::_notification(int p_what) {
cache.font->draw(ci, Point2(cache.style_normal->get_margin(MARGIN_LEFT) + cache.breakpoint_gutter_width + ofs_x, ofs_y + cache.font->get_ascent()), fc, cache.line_number_color);
}
- //loop through charcters in one line
+ //loop through characters in one line
for (int j = 0; j < str.length(); j++) {
//look for keyword
@@ -1025,6 +1025,21 @@ void TextEdit::_notification(int p_what) {
const Color *col = keywords.custom_getptr(range, hash);
+ if (!col) {
+ col = member_keywords.custom_getptr(range, hash);
+
+ if (col) {
+ for (int k = j - 1; k >= 0; k--) {
+ if (str[k] == '.') {
+ col = NULL; //member indexing not allowed
+ break;
+ } else if (str[k] > 32) {
+ break;
+ }
+ }
+ }
+ }
+
if (col) {
in_keyword = true;
@@ -1104,6 +1119,19 @@ void TextEdit::_notification(int p_what) {
if ((char_ofs + char_margin) < xmargin_beg) {
char_ofs += char_w;
+
+ // line highlighting handle horizontal clipping
+ if (line == cursor.line && highlight_current_line) {
+
+ if (j == str.length() - 1) {
+ // end of line when last char is skipped
+ VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg + ofs_x, ofs_y, xmargin_end - (xmargin_beg + ofs_x), get_row_height()), cache.current_line_color);
+
+ } else if ((char_ofs + char_margin) > xmargin_beg) {
+ // char next to margin is skipped
+ VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg + ofs_x, ofs_y, (char_ofs + char_margin) - xmargin_beg, get_row_height()), cache.current_line_color);
+ }
+ }
continue;
}
@@ -1747,15 +1775,16 @@ void TextEdit::indent_left() {
void TextEdit::_get_mouse_pos(const Point2i &p_mouse, int &r_row, int &r_col) const {
float rows = p_mouse.y;
+ rows -= cache.style_normal->get_margin(MARGIN_TOP);
+ rows += (CLAMP(v_scroll->get_value() - get_line_scroll_pos(true), 0, 1) * get_row_height());
rows /= get_row_height();
- rows += v_scroll->get_value();
- int row = Math::floor(rows);
+ int first_vis_line = CLAMP(cursor.line_ofs, 0, text.size() - 1);
+ int row = first_vis_line + Math::floor(rows);
if (is_hiding_enabled()) {
// row will be offset by the hidden rows
- int lsp = get_line_scroll_pos(true);
- int f_ofs = num_lines_from(CLAMP(cursor.line_ofs, 0, text.size() - 1), MIN(row + 1 - cursor.line_ofs, text.size() - cursor.line_ofs)) - 1;
- row = cursor.line_ofs + f_ofs;
+ int f_ofs = num_lines_from(first_vis_line, rows + 1) - 1;
+ row = first_vis_line + f_ofs;
row = CLAMP(row, 0, text.size() - num_lines_from(text.size() - 1, -1));
}
@@ -3102,7 +3131,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
return;
}
- if (!scancode_handled && !k->get_command()) { //for german kbds
+ if (!scancode_handled && !k->get_command()) { //for German kbds
if (k->get_unicode() >= 32) {
@@ -4047,11 +4076,21 @@ void TextEdit::set_wrap(bool p_wrap) {
wrap = p_wrap;
}
+bool TextEdit::is_wrapping() const {
+
+ return wrap;
+}
+
void TextEdit::set_max_chars(int p_max_chars) {
max_chars = p_max_chars;
}
+int TextEdit::get_max_chars() const {
+
+ return max_chars;
+}
+
void TextEdit::_reset_caret_blink_timer() {
if (caret_blink_enabled) {
caret_blink_timer->stop();
@@ -4128,6 +4167,16 @@ void TextEdit::add_color_region(const String &p_begin_key, const String &p_end_k
update();
}
+void TextEdit::add_member_keyword(const String &p_keyword, const Color &p_color) {
+ member_keywords[p_keyword] = p_color;
+ update();
+}
+
+void TextEdit::clear_member_keywords() {
+ member_keywords.clear();
+ update();
+}
+
void TextEdit::set_syntax_coloring(bool p_enabled) {
syntax_coloring = p_enabled;
@@ -4873,6 +4922,8 @@ void TextEdit::undo() {
else
undo_stack_pos = undo_stack_pos->prev();
+ deselect();
+
TextOperation op = undo_stack_pos->get();
_do_text_op(op, true);
current_op.version = op.prev_version;
@@ -4907,6 +4958,8 @@ void TextEdit::redo() {
if (undo_stack_pos == NULL)
return; //nothing to do.
+ deselect();
+
TextOperation op = undo_stack_pos->get();
_do_text_op(op, false);
current_op.version = op.version;
@@ -5573,7 +5626,9 @@ void TextEdit::_bind_methods() {
ClassDB::bind_method(D_METHOD("is_readonly"), &TextEdit::is_readonly);
ClassDB::bind_method(D_METHOD("set_wrap", "enable"), &TextEdit::set_wrap);
- ClassDB::bind_method(D_METHOD("set_max_chars", "amount"), &TextEdit::set_max_chars);
+ ClassDB::bind_method(D_METHOD("is_wrapping"), &TextEdit::is_wrapping);
+ // ClassDB::bind_method(D_METHOD("set_max_chars", "amount"), &TextEdit::set_max_chars);
+ // ClassDB::bind_method(D_METHOD("get_max_char"), &TextEdit::get_max_chars);
ClassDB::bind_method(D_METHOD("set_context_menu_enabled", "enable"), &TextEdit::set_context_menu_enabled);
ClassDB::bind_method(D_METHOD("is_context_menu_enabled"), &TextEdit::is_context_menu_enabled);
@@ -5647,6 +5702,8 @@ void TextEdit::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "smooth_scrolling"), "set_smooth_scroll_enable", "is_smooth_scroll_enabled");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "v_scroll_speed"), "set_v_scroll_speed", "get_v_scroll_speed");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "hiding_enabled"), "set_hiding_enabled", "is_hiding_enabled");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "wrap_lines"), "set_wrap", "is_wrapping");
+ // ADD_PROPERTY(PropertyInfo(Variant::BOOL, "max_chars"), "set_max_chars", "get_max_chars");
ADD_GROUP("Caret", "caret_");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "caret_block_mode"), "cursor_set_block_mode", "cursor_is_block_mode");