You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-18 14:21:41 +00:00
Protect internal CodeEdit --> TextEdit API
This commit is contained in:
@@ -1062,7 +1062,7 @@ void ScriptTextEditor::_edit_option(int p_op) {
|
|||||||
tx->update();
|
tx->update();
|
||||||
} break;
|
} break;
|
||||||
case EDIT_UNFOLD_ALL_LINES: {
|
case EDIT_UNFOLD_ALL_LINES: {
|
||||||
tx->unhide_all_lines();
|
tx->unfold_all_lines();
|
||||||
tx->update();
|
tx->update();
|
||||||
} break;
|
} break;
|
||||||
case EDIT_TOGGLE_COMMENT: {
|
case EDIT_TOGGLE_COMMENT: {
|
||||||
|
|||||||
@@ -340,7 +340,7 @@ void TextEditor::_edit_option(int p_op) {
|
|||||||
tx->update();
|
tx->update();
|
||||||
} break;
|
} break;
|
||||||
case EDIT_UNFOLD_ALL_LINES: {
|
case EDIT_UNFOLD_ALL_LINES: {
|
||||||
tx->unhide_all_lines();
|
tx->unfold_all_lines();
|
||||||
tx->update();
|
tx->update();
|
||||||
} break;
|
} break;
|
||||||
case EDIT_TRIM_TRAILING_WHITESAPCE: {
|
case EDIT_TRIM_TRAILING_WHITESAPCE: {
|
||||||
|
|||||||
@@ -297,7 +297,7 @@ void CodeEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
|
|||||||
if (is_line_folded(line)) {
|
if (is_line_folded(line)) {
|
||||||
int wrap_index = get_line_wrap_index_at_column(line, col);
|
int wrap_index = get_line_wrap_index_at_column(line, col);
|
||||||
if (wrap_index == get_line_wrap_count(line)) {
|
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();
|
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) {
|
if (mpos.x > left_margin && mpos.x <= left_margin + eol_icon_width + 3) {
|
||||||
unfold_line(line);
|
unfold_line(line);
|
||||||
@@ -533,7 +533,7 @@ Control::CursorShape CodeEdit::get_cursor_shape(const Point2 &p_pos) const {
|
|||||||
if (is_line_folded(line)) {
|
if (is_line_folded(line)) {
|
||||||
int wrap_index = get_line_wrap_index_at_column(line, col);
|
int wrap_index = get_line_wrap_index_at_column(line, col);
|
||||||
if (wrap_index == get_line_wrap_count(line)) {
|
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();
|
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) {
|
if (p_pos.x > left_margin && p_pos.x <= left_margin + eol_icon_width + 3) {
|
||||||
return CURSOR_POINTING_HAND;
|
return CURSOR_POINTING_HAND;
|
||||||
@@ -616,7 +616,7 @@ void CodeEdit::_backspace() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cl > 0 && is_line_hidden(cl - 1)) {
|
if (cl > 0 && _is_line_hidden(cl - 1)) {
|
||||||
unfold_line(get_caret_line() - 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 */
|
/* Line Folding */
|
||||||
void CodeEdit::set_line_folding_enabled(bool p_enabled) {
|
void CodeEdit::set_line_folding_enabled(bool p_enabled) {
|
||||||
line_folding_enabled = p_enabled;
|
line_folding_enabled = p_enabled;
|
||||||
set_hiding_enabled(p_enabled);
|
_set_hiding_enabled(p_enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CodeEdit::is_line_folding_enabled() const {
|
bool CodeEdit::is_line_folding_enabled() const {
|
||||||
@@ -1339,7 +1339,7 @@ bool CodeEdit::can_fold_line(int p_line) const {
|
|||||||
return false;
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1419,22 +1419,22 @@ void CodeEdit::fold_line(int p_line) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (int i = p_line + 1; i <= end_line; i++) {
|
for (int i = p_line + 1; i <= end_line; i++) {
|
||||||
set_line_as_hidden(i, true);
|
_set_line_as_hidden(i, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fix selection. */
|
/* Fix selection. */
|
||||||
if (has_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();
|
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());
|
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);
|
select(get_selection_from_line(), get_selection_from_column(), p_line, 9999);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Reset caret. */
|
/* 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_line(p_line, false, false);
|
||||||
set_caret_column(get_line(p_line).length(), 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) {
|
void CodeEdit::unfold_line(int p_line) {
|
||||||
ERR_FAIL_INDEX(p_line, get_line_count());
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1456,10 +1456,10 @@ void CodeEdit::unfold_line(int p_line) {
|
|||||||
fold_start = is_line_folded(fold_start) ? fold_start : p_line;
|
fold_start = is_line_folded(fold_start) ? fold_start : p_line;
|
||||||
|
|
||||||
for (int i = fold_start + 1; i < get_line_count(); i++) {
|
for (int i = fold_start + 1; i < get_line_count(); i++) {
|
||||||
if (!is_line_hidden(i)) {
|
if (!_is_line_hidden(i)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
set_line_as_hidden(i, false);
|
_set_line_as_hidden(i, false);
|
||||||
}
|
}
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
@@ -1472,7 +1472,7 @@ void CodeEdit::fold_all_lines() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CodeEdit::unfold_all_lines() {
|
void CodeEdit::unfold_all_lines() {
|
||||||
unhide_all_lines();
|
_unhide_all_lines();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CodeEdit::toggle_foldable_line(int p_line) {
|
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 {
|
bool CodeEdit::is_line_folded(int p_line) const {
|
||||||
ERR_FAIL_INDEX_V(p_line, get_line_count(), false);
|
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 {
|
TypedArray<int> CodeEdit::get_folded_lines() const {
|
||||||
|
|||||||
@@ -671,7 +671,7 @@ void TextEdit::_notification(int p_what) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (is_line_hidden(minimap_line)) {
|
while (_is_line_hidden(minimap_line)) {
|
||||||
minimap_line++;
|
minimap_line++;
|
||||||
if (minimap_line < 0 || minimap_line >= (int)text.size()) {
|
if (minimap_line < 0 || minimap_line >= (int)text.size()) {
|
||||||
break;
|
break;
|
||||||
@@ -815,7 +815,7 @@ void TextEdit::_notification(int p_what) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (is_line_hidden(line)) {
|
while (_is_line_hidden(line)) {
|
||||||
line++;
|
line++;
|
||||||
if (line < 0 || line >= (int)text.size()) {
|
if (line < 0 || line >= (int)text.size()) {
|
||||||
break;
|
break;
|
||||||
@@ -1175,13 +1175,13 @@ void TextEdit::_notification(int p_what) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// is_line_folded
|
// is_line_folded
|
||||||
if (line_wrap_index == line_wrap_amount && line < text.size() - 1 && is_line_hidden(line + 1)) {
|
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);
|
int xofs = char_ofs + char_margin + ofs_x + (folded_eol_icon->get_width() / 2);
|
||||||
if (xofs >= xmargin_beg && xofs < xmargin_end) {
|
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);
|
int yofs = (text_height - folded_eol_icon->get_height()) / 2 - ldata->get_line_ascent(line_wrap_index);
|
||||||
Color eol_color = cache.code_folding_color;
|
Color eol_color = code_folding_color;
|
||||||
eol_color.a = 1;
|
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 row = first_vis_line + Math::floor(rows);
|
||||||
int wrap_index = 0;
|
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;
|
int f_ofs = num_lines_from_rows(first_vis_line, caret.wrap_ofs, rows + (1 * SGN(rows)), wrap_index) - 1;
|
||||||
if (rows < 0) {
|
if (rows < 0) {
|
||||||
row = first_vis_line - f_ofs;
|
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 row = minimap_line + Math::floor(rows);
|
||||||
int wrap_index = 0;
|
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;
|
int f_ofs = num_lines_from_rows(minimap_line, caret.wrap_ofs, rows + (1 * SGN(rows)), wrap_index) - 1;
|
||||||
if (rows < 0) {
|
if (rows < 0) {
|
||||||
row = minimap_line - f_ofs;
|
row = minimap_line - f_ofs;
|
||||||
@@ -2748,7 +2748,7 @@ int TextEdit::_get_minimap_visible_rows() const {
|
|||||||
int TextEdit::get_total_visible_rows() const {
|
int TextEdit::get_total_visible_rows() const {
|
||||||
// Returns the total amount of rows we need in the editor.
|
// Returns the total amount of rows we need in the editor.
|
||||||
// This skips hidden lines and counts each wrapping of a line.
|
// 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();
|
return text.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2895,7 +2895,7 @@ void TextEdit::_scroll_moved(double p_to_val) {
|
|||||||
int sc = 0;
|
int sc = 0;
|
||||||
int n_line;
|
int n_line;
|
||||||
for (n_line = 0; n_line < text.size(); 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++;
|
||||||
sc += get_line_wrap_count(n_line);
|
sc += get_line_wrap_count(n_line);
|
||||||
if (sc > v_scroll_i) {
|
if (sc > v_scroll_i) {
|
||||||
@@ -3200,6 +3200,10 @@ bool TextEdit::is_readonly() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TextEdit::_update_caches() {
|
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 */
|
||||||
caret_color = get_theme_color(SNAME("caret_color"));
|
caret_color = get_theme_color(SNAME("caret_color"));
|
||||||
caret_background_color = get_theme_color(SNAME("caret_background_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_color = get_theme_color(SNAME("font_color"));
|
||||||
cache.font_readonly_color = get_theme_color(SNAME("font_readonly_color"));
|
cache.font_readonly_color = get_theme_color(SNAME("font_readonly_color"));
|
||||||
cache.current_line_color = get_theme_color(SNAME("current_line_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.brace_mismatch_color = get_theme_color(SNAME("brace_mismatch_color"), SNAME("CodeEdit"));
|
||||||
cache.word_highlighted_color = get_theme_color(SNAME("word_highlighted_color"));
|
cache.word_highlighted_color = get_theme_color(SNAME("word_highlighted_color"));
|
||||||
cache.search_result_color = get_theme_color(SNAME("search_result_color"));
|
cache.search_result_color = get_theme_color(SNAME("search_result_color"));
|
||||||
@@ -3231,7 +3234,6 @@ void TextEdit::_update_caches() {
|
|||||||
#endif
|
#endif
|
||||||
cache.tab_icon = get_theme_icon(SNAME("tab"));
|
cache.tab_icon = get_theme_icon(SNAME("tab"));
|
||||||
cache.space_icon = get_theme_icon(SNAME("space"));
|
cache.space_icon = get_theme_icon(SNAME("space"));
|
||||||
cache.folded_eol_icon = get_theme_icon(SNAME("folded_eol_icon"), SNAME("CodeEdit"));
|
|
||||||
|
|
||||||
TextServer::Direction dir;
|
TextServer::Direction dir;
|
||||||
if (text_direction == Control::TEXT_DIRECTION_INHERITED) {
|
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 (!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;
|
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;
|
p_line += move_down;
|
||||||
} else {
|
} else {
|
||||||
int move_up = num_lines_from(p_line, -1) - 1;
|
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;
|
p_line -= move_up;
|
||||||
} else {
|
} else {
|
||||||
WARN_PRINT(("Caret set to hidden line " + itos(p_line) + " and there are no nonhidden lines."));
|
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;
|
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 {
|
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).
|
// 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));
|
ERR_FAIL_INDEX_V(p_line_from, text.size(), ABS(visible_amount));
|
||||||
|
|
||||||
if (!is_hiding_enabled()) {
|
if (!_is_hiding_enabled()) {
|
||||||
return ABS(visible_amount);
|
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) {
|
if (visible_amount >= 0) {
|
||||||
for (int i = p_line_from; i < text.size(); i++) {
|
for (int i = p_line_from; i < text.size(); i++) {
|
||||||
num_total++;
|
num_total++;
|
||||||
if (!is_line_hidden(i)) {
|
if (!_is_line_hidden(i)) {
|
||||||
num_visible++;
|
num_visible++;
|
||||||
}
|
}
|
||||||
if (num_visible >= visible_amount) {
|
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);
|
visible_amount = ABS(visible_amount);
|
||||||
for (int i = p_line_from; i >= 0; i--) {
|
for (int i = p_line_from; i >= 0; i--) {
|
||||||
num_total++;
|
num_total++;
|
||||||
if (!is_line_hidden(i)) {
|
if (!_is_line_hidden(i)) {
|
||||||
num_visible++;
|
num_visible++;
|
||||||
}
|
}
|
||||||
if (num_visible >= visible_amount) {
|
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;
|
wrap_index = 0;
|
||||||
ERR_FAIL_INDEX_V(p_line_from, text.size(), ABS(visible_amount));
|
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);
|
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;
|
num_visible -= p_wrap_index_from;
|
||||||
for (i = p_line_from; i < text.size(); i++) {
|
for (i = p_line_from; i < text.size(); i++) {
|
||||||
num_total++;
|
num_total++;
|
||||||
if (!is_line_hidden(i)) {
|
if (!_is_line_hidden(i)) {
|
||||||
num_visible++;
|
num_visible++;
|
||||||
num_visible += get_line_wrap_count(i);
|
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;
|
num_visible -= get_line_wrap_count(p_line_from) - p_wrap_index_from;
|
||||||
for (i = p_line_from; i >= 0; i--) {
|
for (i = p_line_from; i >= 0; i--) {
|
||||||
num_total++;
|
num_total++;
|
||||||
if (!is_line_hidden(i)) {
|
if (!_is_line_hidden(i)) {
|
||||||
num_visible++;
|
num_visible++;
|
||||||
num_visible += get_line_wrap_count(i);
|
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 {
|
int TextEdit::get_last_unhidden_line() const {
|
||||||
// Returns the last line in the text that is not hidden.
|
// Returns the last line in the text that is not hidden.
|
||||||
if (!is_hiding_enabled()) {
|
if (!_is_hiding_enabled()) {
|
||||||
return text.size() - 1;
|
return text.size() - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int last_line;
|
int last_line;
|
||||||
for (last_line = text.size() - 1; last_line > 0; 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;
|
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 {
|
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;
|
return p_line;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4791,18 +4772,6 @@ int TextEdit::get_minimap_width() const {
|
|||||||
return minimap_width;
|
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) {
|
void TextEdit::set_highlight_current_line(bool p_enabled) {
|
||||||
highlight_current_line = p_enabled;
|
highlight_current_line = p_enabled;
|
||||||
update();
|
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) {
|
void TextEdit::set_context_menu_enabled(bool p_enable) {
|
||||||
context_menu_enabled = 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);
|
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 */
|
/* Text manipulation */
|
||||||
|
|
||||||
// Overridable actions
|
// Overridable actions
|
||||||
@@ -5477,8 +5482,8 @@ void TextEdit::_backspace() {
|
|||||||
|
|
||||||
merge_gutters(cl, prev_line);
|
merge_gutters(cl, prev_line);
|
||||||
|
|
||||||
if (is_line_hidden(cl)) {
|
if (_is_line_hidden(cl)) {
|
||||||
set_line_as_hidden(prev_line, true);
|
_set_line_as_hidden(prev_line, true);
|
||||||
}
|
}
|
||||||
_remove_text(prev_line, prev_column, cl, cc);
|
_remove_text(prev_line, prev_column, cl, cc);
|
||||||
|
|
||||||
|
|||||||
@@ -339,7 +339,6 @@ private:
|
|||||||
bool draw_spaces = false;
|
bool draw_spaces = false;
|
||||||
bool text_changed_dirty = false;
|
bool text_changed_dirty = false;
|
||||||
bool undo_enabled = true;
|
bool undo_enabled = true;
|
||||||
bool hiding_enabled = false;
|
|
||||||
bool draw_minimap = false;
|
bool draw_minimap = false;
|
||||||
int minimap_width = 80;
|
int minimap_width = 80;
|
||||||
Point2 minimap_char_size = Point2(1, 2);
|
Point2 minimap_char_size = Point2(1, 2);
|
||||||
@@ -361,8 +360,6 @@ private:
|
|||||||
float target_v_scroll = 0.0;
|
float target_v_scroll = 0.0;
|
||||||
float v_scroll_speed = 80.0;
|
float v_scroll_speed = 80.0;
|
||||||
|
|
||||||
String lookup_symbol_word;
|
|
||||||
|
|
||||||
Timer *idle_detect;
|
Timer *idle_detect;
|
||||||
HScrollBar *h_scroll;
|
HScrollBar *h_scroll;
|
||||||
VScrollBar *v_scroll;
|
VScrollBar *v_scroll;
|
||||||
@@ -464,7 +461,6 @@ protected:
|
|||||||
struct Cache {
|
struct Cache {
|
||||||
Ref<Texture2D> tab_icon;
|
Ref<Texture2D> tab_icon;
|
||||||
Ref<Texture2D> space_icon;
|
Ref<Texture2D> space_icon;
|
||||||
Ref<Texture2D> folded_eol_icon;
|
|
||||||
Ref<StyleBox> style_normal;
|
Ref<StyleBox> style_normal;
|
||||||
Ref<StyleBox> style_focus;
|
Ref<StyleBox> style_focus;
|
||||||
Ref<StyleBox> style_readonly;
|
Ref<StyleBox> style_readonly;
|
||||||
@@ -474,7 +470,6 @@ protected:
|
|||||||
Color outline_color;
|
Color outline_color;
|
||||||
Color font_color;
|
Color font_color;
|
||||||
Color font_readonly_color;
|
Color font_readonly_color;
|
||||||
Color code_folding_color;
|
|
||||||
Color current_line_color;
|
Color current_line_color;
|
||||||
Color brace_mismatch_color;
|
Color brace_mismatch_color;
|
||||||
Color word_highlighted_color;
|
Color word_highlighted_color;
|
||||||
@@ -499,6 +494,23 @@ protected:
|
|||||||
bool _get(const StringName &p_name, Variant &r_ret) const;
|
bool _get(const StringName &p_name, Variant &r_ret) const;
|
||||||
void _get_property_list(List<PropertyInfo> *p_list) 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);
|
void _set_symbol_lookup_word(const String &p_symbol);
|
||||||
|
|
||||||
/* Text manipulation */
|
/* Text manipulation */
|
||||||
@@ -716,9 +728,6 @@ public:
|
|||||||
int get_line_count() const;
|
int get_line_count() const;
|
||||||
int get_line_width(int p_line, int p_wrap_offset = -1) 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(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 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;
|
int get_last_unhidden_line() const;
|
||||||
@@ -800,9 +809,6 @@ public:
|
|||||||
void set_minimap_width(int p_minimap_width);
|
void set_minimap_width(int p_minimap_width);
|
||||||
int get_minimap_width() const;
|
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_tooltip_request_func(Object *p_obj, const StringName &p_function, const Variant &p_udata);
|
||||||
|
|
||||||
void set_context_menu_enabled(bool p_enable);
|
void set_context_menu_enabled(bool p_enable);
|
||||||
|
|||||||
Reference in New Issue
Block a user