summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--editor/plugins/script_text_editor.cpp2
-rw-r--r--editor/plugins/text_editor.cpp2
-rw-r--r--scene/gui/code_edit.cpp30
-rw-r--r--scene/gui/text_edit.cpp135
-rw-r--r--scene/gui/text_edit.h28
5 files changed, 104 insertions, 93 deletions
diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp
index ad25bca9da..6d2b22c46c 100644
--- a/editor/plugins/script_text_editor.cpp
+++ b/editor/plugins/script_text_editor.cpp
@@ -1062,7 +1062,7 @@ void ScriptTextEditor::_edit_option(int p_op) {
tx->update();
} break;
case EDIT_UNFOLD_ALL_LINES: {
- tx->unhide_all_lines();
+ tx->unfold_all_lines();
tx->update();
} break;
case EDIT_TOGGLE_COMMENT: {
diff --git a/editor/plugins/text_editor.cpp b/editor/plugins/text_editor.cpp
index 4e90399433..f38bb6e996 100644
--- a/editor/plugins/text_editor.cpp
+++ b/editor/plugins/text_editor.cpp
@@ -340,7 +340,7 @@ void TextEditor::_edit_option(int p_op) {
tx->update();
} break;
case EDIT_UNFOLD_ALL_LINES: {
- tx->unhide_all_lines();
+ tx->unfold_all_lines();
tx->update();
} break;
case EDIT_TRIM_TRAILING_WHITESAPCE: {
diff --git a/scene/gui/code_edit.cpp b/scene/gui/code_edit.cpp
index 134151dbe8..aabfde88ff 100644
--- a/scene/gui/code_edit.cpp
+++ b/scene/gui/code_edit.cpp
@@ -297,7 +297,7 @@ void CodeEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
if (is_line_folded(line)) {
int wrap_index = get_line_wrap_index_at_column(line, col);
if (wrap_index == get_line_wrap_count(line)) {
- int eol_icon_width = cache.folded_eol_icon->get_width();
+ int eol_icon_width = folded_eol_icon->get_width();
int left_margin = get_total_gutter_width() + eol_icon_width + get_line_width(line, wrap_index) - get_h_scroll();
if (mpos.x > left_margin && mpos.x <= left_margin + eol_icon_width + 3) {
unfold_line(line);
@@ -533,7 +533,7 @@ Control::CursorShape CodeEdit::get_cursor_shape(const Point2 &p_pos) const {
if (is_line_folded(line)) {
int wrap_index = get_line_wrap_index_at_column(line, col);
if (wrap_index == get_line_wrap_count(line)) {
- int eol_icon_width = cache.folded_eol_icon->get_width();
+ int eol_icon_width = folded_eol_icon->get_width();
int left_margin = get_total_gutter_width() + eol_icon_width + get_line_width(line, wrap_index) - get_h_scroll();
if (p_pos.x > left_margin && p_pos.x <= left_margin + eol_icon_width + 3) {
return CURSOR_POINTING_HAND;
@@ -616,7 +616,7 @@ void CodeEdit::_backspace() {
return;
}
- if (cl > 0 && is_line_hidden(cl - 1)) {
+ if (cl > 0 && _is_line_hidden(cl - 1)) {
unfold_line(get_caret_line() - 1);
}
@@ -1322,7 +1322,7 @@ void CodeEdit::_fold_gutter_draw_callback(int p_line, int p_gutter, Rect2 p_regi
/* Line Folding */
void CodeEdit::set_line_folding_enabled(bool p_enabled) {
line_folding_enabled = p_enabled;
- set_hiding_enabled(p_enabled);
+ _set_hiding_enabled(p_enabled);
}
bool CodeEdit::is_line_folding_enabled() const {
@@ -1339,7 +1339,7 @@ bool CodeEdit::can_fold_line(int p_line) const {
return false;
}
- if (is_line_hidden(p_line) || is_line_folded(p_line)) {
+ if (_is_line_hidden(p_line) || is_line_folded(p_line)) {
return false;
}
@@ -1419,22 +1419,22 @@ void CodeEdit::fold_line(int p_line) {
}
for (int i = p_line + 1; i <= end_line; i++) {
- set_line_as_hidden(i, true);
+ _set_line_as_hidden(i, true);
}
/* Fix selection. */
if (has_selection()) {
- if (is_line_hidden(get_selection_from_line()) && is_line_hidden(get_selection_to_line())) {
+ if (_is_line_hidden(get_selection_from_line()) && _is_line_hidden(get_selection_to_line())) {
deselect();
- } else if (is_line_hidden(get_selection_from_line())) {
+ } else if (_is_line_hidden(get_selection_from_line())) {
select(p_line, 9999, get_selection_to_line(), get_selection_to_column());
- } else if (is_line_hidden(get_selection_to_line())) {
+ } else if (_is_line_hidden(get_selection_to_line())) {
select(get_selection_from_line(), get_selection_from_column(), p_line, 9999);
}
}
/* Reset caret. */
- if (is_line_hidden(get_caret_line())) {
+ if (_is_line_hidden(get_caret_line())) {
set_caret_line(p_line, false, false);
set_caret_column(get_line(p_line).length(), false);
}
@@ -1443,7 +1443,7 @@ void CodeEdit::fold_line(int p_line) {
void CodeEdit::unfold_line(int p_line) {
ERR_FAIL_INDEX(p_line, get_line_count());
- if (!is_line_folded(p_line) && !is_line_hidden(p_line)) {
+ if (!is_line_folded(p_line) && !_is_line_hidden(p_line)) {
return;
}
@@ -1456,10 +1456,10 @@ void CodeEdit::unfold_line(int p_line) {
fold_start = is_line_folded(fold_start) ? fold_start : p_line;
for (int i = fold_start + 1; i < get_line_count(); i++) {
- if (!is_line_hidden(i)) {
+ if (!_is_line_hidden(i)) {
break;
}
- set_line_as_hidden(i, false);
+ _set_line_as_hidden(i, false);
}
update();
}
@@ -1472,7 +1472,7 @@ void CodeEdit::fold_all_lines() {
}
void CodeEdit::unfold_all_lines() {
- unhide_all_lines();
+ _unhide_all_lines();
}
void CodeEdit::toggle_foldable_line(int p_line) {
@@ -1486,7 +1486,7 @@ void CodeEdit::toggle_foldable_line(int p_line) {
bool CodeEdit::is_line_folded(int p_line) const {
ERR_FAIL_INDEX_V(p_line, get_line_count(), false);
- return p_line + 1 < get_line_count() && !is_line_hidden(p_line) && is_line_hidden(p_line + 1);
+ return p_line + 1 < get_line_count() && !_is_line_hidden(p_line) && _is_line_hidden(p_line + 1);
}
TypedArray<int> CodeEdit::get_folded_lines() const {
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index 5cd95fbbf7..bcd4cbd7f3 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -671,7 +671,7 @@ void TextEdit::_notification(int p_what) {
break;
}
- while (is_line_hidden(minimap_line)) {
+ while (_is_line_hidden(minimap_line)) {
minimap_line++;
if (minimap_line < 0 || minimap_line >= (int)text.size()) {
break;
@@ -815,7 +815,7 @@ void TextEdit::_notification(int p_what) {
continue;
}
- while (is_line_hidden(line)) {
+ while (_is_line_hidden(line)) {
line++;
if (line < 0 || line >= (int)text.size()) {
break;
@@ -1175,13 +1175,13 @@ void TextEdit::_notification(int p_what) {
}
// is_line_folded
- if (line_wrap_index == line_wrap_amount && line < text.size() - 1 && is_line_hidden(line + 1)) {
- int xofs = char_ofs + char_margin + ofs_x + (cache.folded_eol_icon->get_width() / 2);
+ if (line_wrap_index == line_wrap_amount && line < text.size() - 1 && _is_line_hidden(line + 1)) {
+ int xofs = char_ofs + char_margin + ofs_x + (folded_eol_icon->get_width() / 2);
if (xofs >= xmargin_beg && xofs < xmargin_end) {
- int yofs = (text_height - cache.folded_eol_icon->get_height()) / 2 - ldata->get_line_ascent(line_wrap_index);
- Color eol_color = cache.code_folding_color;
+ int yofs = (text_height - folded_eol_icon->get_height()) / 2 - ldata->get_line_ascent(line_wrap_index);
+ Color eol_color = code_folding_color;
eol_color.a = 1;
- cache.folded_eol_icon->draw(ci, Point2(xofs, ofs_y + yofs), eol_color);
+ folded_eol_icon->draw(ci, Point2(xofs, ofs_y + yofs), eol_color);
}
}
@@ -1802,7 +1802,7 @@ void TextEdit::_get_mouse_pos(const Point2i &p_mouse, int &r_row, int &r_col) co
int row = first_vis_line + Math::floor(rows);
int wrap_index = 0;
- if (get_line_wrapping_mode() != LineWrappingMode::LINE_WRAPPING_NONE || is_hiding_enabled()) {
+ if (get_line_wrapping_mode() != LineWrappingMode::LINE_WRAPPING_NONE || _is_hiding_enabled()) {
int f_ofs = num_lines_from_rows(first_vis_line, caret.wrap_ofs, rows + (1 * SGN(rows)), wrap_index) - 1;
if (rows < 0) {
row = first_vis_line - f_ofs;
@@ -1880,7 +1880,7 @@ void TextEdit::_get_minimap_mouse_row(const Point2i &p_mouse, int &r_row) const
int row = minimap_line + Math::floor(rows);
int wrap_index = 0;
- if (get_line_wrapping_mode() != LineWrappingMode::LINE_WRAPPING_NONE || is_hiding_enabled()) {
+ if (get_line_wrapping_mode() != LineWrappingMode::LINE_WRAPPING_NONE || _is_hiding_enabled()) {
int f_ofs = num_lines_from_rows(minimap_line, caret.wrap_ofs, rows + (1 * SGN(rows)), wrap_index) - 1;
if (rows < 0) {
row = minimap_line - f_ofs;
@@ -2748,7 +2748,7 @@ int TextEdit::_get_minimap_visible_rows() const {
int TextEdit::get_total_visible_rows() const {
// Returns the total amount of rows we need in the editor.
// This skips hidden lines and counts each wrapping of a line.
- if (!is_hiding_enabled() && get_line_wrapping_mode() == LineWrappingMode::LINE_WRAPPING_NONE) {
+ if (!_is_hiding_enabled() && get_line_wrapping_mode() == LineWrappingMode::LINE_WRAPPING_NONE) {
return text.size();
}
@@ -2895,7 +2895,7 @@ void TextEdit::_scroll_moved(double p_to_val) {
int sc = 0;
int n_line;
for (n_line = 0; n_line < text.size(); n_line++) {
- if (!is_line_hidden(n_line)) {
+ if (!_is_line_hidden(n_line)) {
sc++;
sc += get_line_wrap_count(n_line);
if (sc > v_scroll_i) {
@@ -3200,6 +3200,10 @@ bool TextEdit::is_readonly() const {
}
void TextEdit::_update_caches() {
+ /* Internal API for CodeEdit. */
+ code_folding_color = get_theme_color(SNAME("code_folding_color"), SNAME("CodeEdit"));
+ folded_eol_icon = get_theme_icon(SNAME("folded_eol_icon"), SNAME("CodeEdit"));
+
/* Caret */
caret_color = get_theme_color(SNAME("caret_color"));
caret_background_color = get_theme_color(SNAME("caret_background_color"));
@@ -3218,7 +3222,6 @@ void TextEdit::_update_caches() {
cache.font_color = get_theme_color(SNAME("font_color"));
cache.font_readonly_color = get_theme_color(SNAME("font_readonly_color"));
cache.current_line_color = get_theme_color(SNAME("current_line_color"));
- cache.code_folding_color = get_theme_color(SNAME("code_folding_color"), SNAME("CodeEdit"));
cache.brace_mismatch_color = get_theme_color(SNAME("brace_mismatch_color"), SNAME("CodeEdit"));
cache.word_highlighted_color = get_theme_color(SNAME("word_highlighted_color"));
cache.search_result_color = get_theme_color(SNAME("search_result_color"));
@@ -3231,7 +3234,6 @@ void TextEdit::_update_caches() {
#endif
cache.tab_icon = get_theme_icon(SNAME("tab"));
cache.space_icon = get_theme_icon(SNAME("space"));
- cache.folded_eol_icon = get_theme_icon(SNAME("folded_eol_icon"), SNAME("CodeEdit"));
TextServer::Direction dir;
if (text_direction == Control::TEXT_DIRECTION_INHERITED) {
@@ -3374,13 +3376,13 @@ void TextEdit::set_caret_line(int p_line, bool p_adjust_viewport, bool p_can_be_
}
if (!p_can_be_hidden) {
- if (is_line_hidden(CLAMP(p_line, 0, text.size() - 1))) {
+ if (_is_line_hidden(CLAMP(p_line, 0, text.size() - 1))) {
int move_down = num_lines_from(p_line, 1) - 1;
- if (p_line + move_down <= text.size() - 1 && !is_line_hidden(p_line + move_down)) {
+ if (p_line + move_down <= text.size() - 1 && !_is_line_hidden(p_line + move_down)) {
p_line += move_down;
} else {
int move_up = num_lines_from(p_line, -1) - 1;
- if (p_line - move_up > 0 && !is_line_hidden(p_line - move_up)) {
+ if (p_line - move_up > 0 && !_is_line_hidden(p_line - move_up)) {
p_line -= move_up;
} else {
WARN_PRINT(("Caret set to hidden line " + itos(p_line) + " and there are no nonhidden lines."));
@@ -4182,32 +4184,11 @@ void TextEdit::_text_changed_emit() {
text_changed_dirty = false;
}
-void TextEdit::set_line_as_hidden(int p_line, bool p_hidden) {
- ERR_FAIL_INDEX(p_line, text.size());
- if (is_hiding_enabled() || !p_hidden) {
- text.set_hidden(p_line, p_hidden);
- }
- update();
-}
-
-bool TextEdit::is_line_hidden(int p_line) const {
- ERR_FAIL_INDEX_V(p_line, text.size(), false);
- return text.is_hidden(p_line);
-}
-
-void TextEdit::unhide_all_lines() {
- for (int i = 0; i < text.size(); i++) {
- text.set_hidden(i, false);
- }
- _update_scrollbars();
- update();
-}
-
int TextEdit::num_lines_from(int p_line_from, int visible_amount) const {
// Returns the number of lines (hidden and unhidden) from p_line_from to (p_line_from + visible_amount of unhidden lines).
ERR_FAIL_INDEX_V(p_line_from, text.size(), ABS(visible_amount));
- if (!is_hiding_enabled()) {
+ if (!_is_hiding_enabled()) {
return ABS(visible_amount);
}
@@ -4216,7 +4197,7 @@ int TextEdit::num_lines_from(int p_line_from, int visible_amount) const {
if (visible_amount >= 0) {
for (int i = p_line_from; i < text.size(); i++) {
num_total++;
- if (!is_line_hidden(i)) {
+ if (!_is_line_hidden(i)) {
num_visible++;
}
if (num_visible >= visible_amount) {
@@ -4227,7 +4208,7 @@ int TextEdit::num_lines_from(int p_line_from, int visible_amount) const {
visible_amount = ABS(visible_amount);
for (int i = p_line_from; i >= 0; i--) {
num_total++;
- if (!is_line_hidden(i)) {
+ if (!_is_line_hidden(i)) {
num_visible++;
}
if (num_visible >= visible_amount) {
@@ -4244,7 +4225,7 @@ int TextEdit::num_lines_from_rows(int p_line_from, int p_wrap_index_from, int vi
wrap_index = 0;
ERR_FAIL_INDEX_V(p_line_from, text.size(), ABS(visible_amount));
- if (!is_hiding_enabled() && get_line_wrapping_mode() == LineWrappingMode::LINE_WRAPPING_NONE) {
+ if (!_is_hiding_enabled() && get_line_wrapping_mode() == LineWrappingMode::LINE_WRAPPING_NONE) {
return ABS(visible_amount);
}
@@ -4258,7 +4239,7 @@ int TextEdit::num_lines_from_rows(int p_line_from, int p_wrap_index_from, int vi
num_visible -= p_wrap_index_from;
for (i = p_line_from; i < text.size(); i++) {
num_total++;
- if (!is_line_hidden(i)) {
+ if (!_is_line_hidden(i)) {
num_visible++;
num_visible += get_line_wrap_count(i);
}
@@ -4273,7 +4254,7 @@ int TextEdit::num_lines_from_rows(int p_line_from, int p_wrap_index_from, int vi
num_visible -= get_line_wrap_count(p_line_from) - p_wrap_index_from;
for (i = p_line_from; i >= 0; i--) {
num_total++;
- if (!is_line_hidden(i)) {
+ if (!_is_line_hidden(i)) {
num_visible++;
num_visible += get_line_wrap_count(i);
}
@@ -4289,13 +4270,13 @@ int TextEdit::num_lines_from_rows(int p_line_from, int p_wrap_index_from, int vi
int TextEdit::get_last_unhidden_line() const {
// Returns the last line in the text that is not hidden.
- if (!is_hiding_enabled()) {
+ if (!_is_hiding_enabled()) {
return text.size() - 1;
}
int last_line;
for (last_line = text.size() - 1; last_line > 0; last_line--) {
- if (!is_line_hidden(last_line)) {
+ if (!_is_line_hidden(last_line)) {
break;
}
}
@@ -4561,7 +4542,7 @@ void TextEdit::tag_saved_version() {
}
double TextEdit::get_scroll_pos_for_line(int p_line, int p_wrap_index) const {
- if (get_line_wrapping_mode() == LineWrappingMode::LINE_WRAPPING_NONE && !is_hiding_enabled()) {
+ if (get_line_wrapping_mode() == LineWrappingMode::LINE_WRAPPING_NONE && !_is_hiding_enabled()) {
return p_line;
}
@@ -4791,18 +4772,6 @@ int TextEdit::get_minimap_width() const {
return minimap_width;
}
-void TextEdit::set_hiding_enabled(bool p_enabled) {
- if (!p_enabled) {
- unhide_all_lines();
- }
- hiding_enabled = p_enabled;
- update();
-}
-
-bool TextEdit::is_hiding_enabled() const {
- return hiding_enabled;
-}
-
void TextEdit::set_highlight_current_line(bool p_enabled) {
highlight_current_line = p_enabled;
update();
@@ -4943,11 +4912,6 @@ void TextEdit::menu_option(int p_option) {
}
}
-void TextEdit::_set_symbol_lookup_word(const String &p_symbol) {
- lookup_symbol_word = p_symbol;
- update();
-}
-
void TextEdit::set_context_menu_enabled(bool p_enable) {
context_menu_enabled = p_enable;
}
@@ -5421,6 +5385,47 @@ void TextEdit::_ensure_menu() {
menu_dir->set_item_checked(menu_dir->get_item_index(MENU_DIR_RTL), text_direction == TEXT_DIRECTION_RTL);
}
+/* Internal API for CodeEdit. */
+// Line hiding.
+void TextEdit::_set_hiding_enabled(bool p_enabled) {
+ if (!p_enabled) {
+ _unhide_all_lines();
+ }
+ hiding_enabled = p_enabled;
+ update();
+}
+
+bool TextEdit::_is_hiding_enabled() const {
+ return hiding_enabled;
+}
+
+bool TextEdit::_is_line_hidden(int p_line) const {
+ ERR_FAIL_INDEX_V(p_line, text.size(), false);
+ return text.is_hidden(p_line);
+}
+
+void TextEdit::_unhide_all_lines() {
+ for (int i = 0; i < text.size(); i++) {
+ text.set_hidden(i, false);
+ }
+ _update_scrollbars();
+ update();
+}
+
+void TextEdit::_set_line_as_hidden(int p_line, bool p_hidden) {
+ ERR_FAIL_INDEX(p_line, text.size());
+ if (_is_hiding_enabled() || !p_hidden) {
+ text.set_hidden(p_line, p_hidden);
+ }
+ update();
+}
+
+// Symbol lookup.
+void TextEdit::_set_symbol_lookup_word(const String &p_symbol) {
+ lookup_symbol_word = p_symbol;
+ update();
+}
+
/* Text manipulation */
// Overridable actions
@@ -5477,8 +5482,8 @@ void TextEdit::_backspace() {
merge_gutters(cl, prev_line);
- if (is_line_hidden(cl)) {
- set_line_as_hidden(prev_line, true);
+ if (_is_line_hidden(cl)) {
+ _set_line_as_hidden(prev_line, true);
}
_remove_text(prev_line, prev_column, cl, cc);
diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h
index 84ee356673..14d5db49e2 100644
--- a/scene/gui/text_edit.h
+++ b/scene/gui/text_edit.h
@@ -339,7 +339,6 @@ private:
bool draw_spaces = false;
bool text_changed_dirty = false;
bool undo_enabled = true;
- bool hiding_enabled = false;
bool draw_minimap = false;
int minimap_width = 80;
Point2 minimap_char_size = Point2(1, 2);
@@ -361,8 +360,6 @@ private:
float target_v_scroll = 0.0;
float v_scroll_speed = 80.0;
- String lookup_symbol_word;
-
Timer *idle_detect;
HScrollBar *h_scroll;
VScrollBar *v_scroll;
@@ -464,7 +461,6 @@ protected:
struct Cache {
Ref<Texture2D> tab_icon;
Ref<Texture2D> space_icon;
- Ref<Texture2D> folded_eol_icon;
Ref<StyleBox> style_normal;
Ref<StyleBox> style_focus;
Ref<StyleBox> style_readonly;
@@ -474,7 +470,6 @@ protected:
Color outline_color;
Color font_color;
Color font_readonly_color;
- Color code_folding_color;
Color current_line_color;
Color brace_mismatch_color;
Color word_highlighted_color;
@@ -499,6 +494,23 @@ protected:
bool _get(const StringName &p_name, Variant &r_ret) const;
void _get_property_list(List<PropertyInfo> *p_list) const;
+ /* Internal API for CodeEdit, pending public API. */
+ // Line hiding.
+ Color code_folding_color = Color(1, 1, 1);
+ Ref<Texture2D> folded_eol_icon;
+
+ bool hiding_enabled = false;
+
+ void _set_hiding_enabled(bool p_enabled);
+ bool _is_hiding_enabled() const;
+
+ void _set_line_as_hidden(int p_line, bool p_hidden);
+ bool _is_line_hidden(int p_line) const;
+
+ void _unhide_all_lines();
+
+ // Symbol lookup.
+ String lookup_symbol_word;
void _set_symbol_lookup_word(const String &p_symbol);
/* Text manipulation */
@@ -716,9 +728,6 @@ public:
int get_line_count() const;
int get_line_width(int p_line, int p_wrap_offset = -1) const;
- void set_line_as_hidden(int p_line, bool p_hidden);
- bool is_line_hidden(int p_line) const;
- void unhide_all_lines();
int num_lines_from(int p_line_from, int visible_amount) const;
int num_lines_from_rows(int p_line_from, int p_wrap_index_from, int visible_amount, int &wrap_index) const;
int get_last_unhidden_line() const;
@@ -800,9 +809,6 @@ public:
void set_minimap_width(int p_minimap_width);
int get_minimap_width() const;
- void set_hiding_enabled(bool p_enabled);
- bool is_hiding_enabled() const;
-
void set_tooltip_request_func(Object *p_obj, const StringName &p_function, const Variant &p_udata);
void set_context_menu_enabled(bool p_enable);