Base accessibility API.
This commit is contained in:
@ -224,9 +224,35 @@ _FORCE_INLINE_ const String &TextEdit::Text::get_text_with_ime(int p_line) const
|
||||
}
|
||||
}
|
||||
|
||||
const Vector<RID> TextEdit::Text::get_accessibility_elements(int p_line) {
|
||||
ERR_FAIL_INDEX_V(p_line, text.size(), Vector<RID>());
|
||||
|
||||
return text[p_line].accessibility_text_root_element;
|
||||
}
|
||||
|
||||
void TextEdit::Text::update_accessibility(int p_line, RID p_root) {
|
||||
ERR_FAIL_INDEX(p_line, text.size());
|
||||
|
||||
Line &l = text.write[p_line];
|
||||
if (l.accessibility_text_root_element.is_empty()) {
|
||||
for (int i = 0; i < l.data_buf->get_line_count(); i++) {
|
||||
RID rid = DisplayServer::get_singleton()->accessibility_create_sub_text_edit_elements(p_root, l.data_buf->get_line_rid(i), max_line_height, p_line);
|
||||
l.accessibility_text_root_element.push_back(rid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TextEdit::Text::invalidate_cache(int p_line, bool p_text_changed) {
|
||||
ERR_FAIL_INDEX(p_line, text.size());
|
||||
|
||||
Line &l = text.write[p_line];
|
||||
for (const RID rid : l.accessibility_text_root_element) {
|
||||
if (rid.is_valid()) {
|
||||
DisplayServer::get_singleton()->accessibility_free_element(rid);
|
||||
}
|
||||
}
|
||||
l.accessibility_text_root_element.clear();
|
||||
|
||||
if (font.is_null()) {
|
||||
return; // Not in tree?
|
||||
}
|
||||
@ -564,8 +590,173 @@ String TextEdit::Text::get_enabled_word_separators() const {
|
||||
/// TEXT EDIT ///
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void TextEdit::_accessibility_action_set_selection(const Variant &p_data) {
|
||||
Dictionary new_selection = p_data;
|
||||
RID sel_start = new_selection["start_element"];
|
||||
Vector2i sel_start_line = DisplayServer::get_singleton()->accessibility_element_get_meta(sel_start);
|
||||
int sel_start_pos = new_selection["start_char"];
|
||||
|
||||
RID sel_end = new_selection["end_element"];
|
||||
Vector2i sel_end_line = DisplayServer::get_singleton()->accessibility_element_get_meta(sel_end);
|
||||
int sel_end_pos = new_selection["end_char"];
|
||||
|
||||
remove_secondary_carets();
|
||||
select(sel_start_line.x, sel_start_pos, sel_end_line.x, sel_end_pos, 0);
|
||||
}
|
||||
|
||||
void TextEdit::_accessibility_action_replace_selected(const Variant &p_data) {
|
||||
String new_text = p_data;
|
||||
insert_text_at_caret(new_text);
|
||||
}
|
||||
|
||||
void TextEdit::_accessibility_action_set_value(const Variant &p_data) {
|
||||
String new_text = p_data;
|
||||
set_text(new_text);
|
||||
}
|
||||
|
||||
void TextEdit::_accessibility_action_menu(const Variant &p_data) {
|
||||
if (context_menu_enabled) {
|
||||
_update_context_menu();
|
||||
adjust_viewport_to_caret();
|
||||
menu->set_position(get_screen_position() + get_caret_draw_pos());
|
||||
menu->reset_size();
|
||||
menu->popup();
|
||||
menu->grab_focus();
|
||||
}
|
||||
}
|
||||
|
||||
void TextEdit::_accessibility_scroll_down(const Variant &p_data) {
|
||||
v_scroll->set_value(v_scroll->get_value() + v_scroll->get_page() / 4);
|
||||
queue_accessibility_update();
|
||||
}
|
||||
|
||||
void TextEdit::_accessibility_scroll_left(const Variant &p_data) {
|
||||
h_scroll->set_value(h_scroll->get_value() - h_scroll->get_page() / 4);
|
||||
queue_accessibility_update();
|
||||
}
|
||||
|
||||
void TextEdit::_accessibility_scroll_right(const Variant &p_data) {
|
||||
h_scroll->set_value(h_scroll->get_value() + h_scroll->get_page() / 4);
|
||||
queue_accessibility_update();
|
||||
}
|
||||
|
||||
void TextEdit::_accessibility_scroll_up(const Variant &p_data) {
|
||||
v_scroll->set_value(v_scroll->get_value() - v_scroll->get_page() / 4);
|
||||
queue_accessibility_update();
|
||||
}
|
||||
|
||||
void TextEdit::_accessibility_scroll_set(const Variant &p_data) {
|
||||
const Point2 &pos = p_data;
|
||||
h_scroll->set_value(pos.x);
|
||||
v_scroll->set_value(pos.y);
|
||||
queue_accessibility_update();
|
||||
}
|
||||
|
||||
void TextEdit::_accessibility_action_scroll_into_view(const Variant &p_data, int p_line, int p_wrap) {
|
||||
double delta = get_scroll_pos_for_line(p_line, p_wrap) - get_v_scroll();
|
||||
if (delta < 0) {
|
||||
_scroll_up(-delta, false);
|
||||
} else {
|
||||
_scroll_down(delta, false);
|
||||
}
|
||||
}
|
||||
|
||||
void TextEdit::_notification(int p_what) {
|
||||
switch (p_what) {
|
||||
case NOTIFICATION_EXIT_TREE:
|
||||
case NOTIFICATION_ACCESSIBILITY_INVALIDATE: {
|
||||
text.clear_accessibility();
|
||||
accessibility_text_root_element_nl = RID();
|
||||
} break;
|
||||
|
||||
case NOTIFICATION_ACCESSIBILITY_UPDATE: {
|
||||
RID ae = get_accessibility_element();
|
||||
ERR_FAIL_COND(ae.is_null());
|
||||
|
||||
DisplayServer::get_singleton()->accessibility_update_set_role(ae, DisplayServer::AccessibilityRole::ROLE_MULTILINE_TEXT_FIELD);
|
||||
if (text.size() == 1 && text[0].is_empty()) {
|
||||
DisplayServer::get_singleton()->accessibility_update_set_placeholder(ae, atr(placeholder_text));
|
||||
}
|
||||
if (!placeholder_text.is_empty() && get_accessibility_name().is_empty()) {
|
||||
DisplayServer::get_singleton()->accessibility_update_set_name(ae, atr(placeholder_text));
|
||||
}
|
||||
DisplayServer::get_singleton()->accessibility_update_set_flag(ae, DisplayServer::AccessibilityFlags::FLAG_READONLY, !editable);
|
||||
DisplayServer::get_singleton()->accessibility_update_add_action(ae, DisplayServer::AccessibilityAction::ACTION_SET_TEXT_SELECTION, callable_mp(this, &TextEdit::_accessibility_action_set_selection));
|
||||
DisplayServer::get_singleton()->accessibility_update_add_action(ae, DisplayServer::AccessibilityAction::ACTION_REPLACE_SELECTED_TEXT, callable_mp(this, &TextEdit::_accessibility_action_replace_selected));
|
||||
DisplayServer::get_singleton()->accessibility_update_add_action(ae, DisplayServer::AccessibilityAction::ACTION_SET_VALUE, callable_mp(this, &TextEdit::_accessibility_action_set_value));
|
||||
DisplayServer::get_singleton()->accessibility_update_add_action(ae, DisplayServer::AccessibilityAction::ACTION_SHOW_CONTEXT_MENU, callable_mp(this, &TextEdit::_accessibility_action_menu));
|
||||
|
||||
DisplayServer::get_singleton()->accessibility_update_add_action(ae, DisplayServer::AccessibilityAction::ACTION_SCROLL_DOWN, callable_mp(this, &TextEdit::_accessibility_scroll_down));
|
||||
DisplayServer::get_singleton()->accessibility_update_add_action(ae, DisplayServer::AccessibilityAction::ACTION_SCROLL_LEFT, callable_mp(this, &TextEdit::_accessibility_scroll_left));
|
||||
DisplayServer::get_singleton()->accessibility_update_add_action(ae, DisplayServer::AccessibilityAction::ACTION_SCROLL_RIGHT, callable_mp(this, &TextEdit::_accessibility_scroll_right));
|
||||
DisplayServer::get_singleton()->accessibility_update_add_action(ae, DisplayServer::AccessibilityAction::ACTION_SCROLL_UP, callable_mp(this, &TextEdit::_accessibility_scroll_up));
|
||||
DisplayServer::get_singleton()->accessibility_update_add_action(ae, DisplayServer::AccessibilityAction::ACTION_SET_SCROLL_OFFSET, callable_mp(this, &TextEdit::_accessibility_scroll_set));
|
||||
|
||||
int first_vis_line = get_first_visible_line();
|
||||
int row_height = get_line_height();
|
||||
int xmargin_beg = theme_cache.style_normal->get_margin(SIDE_LEFT) + gutters_width + gutter_padding;
|
||||
Size2 size = get_size();
|
||||
bool rtl = is_layout_rtl();
|
||||
int lines_drawn = 0;
|
||||
|
||||
RID selection_start;
|
||||
RID selection_end;
|
||||
|
||||
for (int i = 0; i < text.size(); i++) {
|
||||
text.update_accessibility(i, ae);
|
||||
const Ref<TextParagraph> &ac_buf = text.get_line_data(i);
|
||||
const Vector<RID> &text_aes = text.get_accessibility_elements(i);
|
||||
for (int j = 0; j < text_aes.size(); j++) {
|
||||
float text_off_x = 0.0;
|
||||
float text_off_y = 0.0;
|
||||
if (!editable) {
|
||||
text_off_x = theme_cache.style_readonly->get_offset().x / 2;
|
||||
text_off_x -= theme_cache.style_normal->get_offset().x / 2;
|
||||
text_off_y = theme_cache.style_readonly->get_offset().y / 2;
|
||||
} else {
|
||||
text_off_y = theme_cache.style_normal->get_offset().y / 2;
|
||||
}
|
||||
|
||||
text_off_y += (lines_drawn + j) * row_height + theme_cache.line_spacing / 2;
|
||||
text_off_y -= (first_vis_line + first_visible_line_wrap_ofs) * row_height;
|
||||
text_off_y -= _get_v_scroll_offset() * row_height;
|
||||
|
||||
int char_margin = xmargin_beg - first_visible_col;
|
||||
if (rtl) {
|
||||
char_margin = size.width - char_margin - ac_buf->get_line_width(j);
|
||||
}
|
||||
|
||||
DisplayServer::get_singleton()->accessibility_update_set_flag(text_aes[j], DisplayServer::AccessibilityFlags::FLAG_HIDDEN, _is_line_hidden(i));
|
||||
Transform2D tr;
|
||||
tr.set_origin(Point2(char_margin + text_off_x, text_off_y));
|
||||
DisplayServer::get_singleton()->accessibility_update_set_transform(text_aes[j], tr);
|
||||
DisplayServer::get_singleton()->accessibility_update_set_name(text_aes[j], vformat(RTR("Line %d"), i));
|
||||
DisplayServer::get_singleton()->accessibility_element_set_meta(text_aes[j], Vector2i(i, j));
|
||||
DisplayServer::get_singleton()->accessibility_update_add_action(text_aes[j], DisplayServer::AccessibilityAction::ACTION_SCROLL_INTO_VIEW, callable_mp(this, &TextEdit::_accessibility_action_scroll_into_view).bind(i, j));
|
||||
}
|
||||
lines_drawn += ac_buf->get_line_count();
|
||||
}
|
||||
if (accessibility_text_root_element_nl.is_null()) {
|
||||
accessibility_text_root_element_nl = DisplayServer::get_singleton()->accessibility_create_sub_text_edit_elements(ae, RID(), get_line_height());
|
||||
}
|
||||
|
||||
// Selection.
|
||||
if (carets.size() > 0) {
|
||||
if (carets[0].selection.active) {
|
||||
int start_wrap = get_line_wrap_index_at_column(carets[0].selection.origin_line, carets[0].selection.origin_column);
|
||||
RID start_rid = text.get_accessibility_elements(carets[0].selection.origin_line)[start_wrap];
|
||||
|
||||
int end_wrap = get_line_wrap_index_at_column(carets[0].line, carets[0].column);
|
||||
RID end_rid = text.get_accessibility_elements(carets[0].line)[end_wrap];
|
||||
DisplayServer::get_singleton()->accessibility_update_set_text_selection(ae, start_rid, carets[0].selection.origin_column, end_rid, carets[0].column);
|
||||
} else {
|
||||
int caret_wrap = get_line_wrap_index_at_column(carets[0].line, carets[0].column);
|
||||
RID caret_rid = text.get_accessibility_elements(carets[0].line)[caret_wrap];
|
||||
DisplayServer::get_singleton()->accessibility_update_set_text_selection(ae, caret_rid, carets[0].column, caret_rid, carets[0].column);
|
||||
}
|
||||
}
|
||||
} break;
|
||||
|
||||
case NOTIFICATION_POSTINITIALIZE: {
|
||||
_update_caches();
|
||||
} break;
|
||||
@ -1694,6 +1885,8 @@ void TextEdit::_notification(int p_what) {
|
||||
|
||||
_update_ime_text();
|
||||
adjust_viewport_to_caret(0);
|
||||
|
||||
queue_accessibility_update();
|
||||
queue_redraw();
|
||||
}
|
||||
} break;
|
||||
@ -1864,6 +2057,7 @@ void TextEdit::gui_input(const Ref<InputEvent> &p_gui_input) {
|
||||
if (mb->get_button_index() == MouseButton::WHEEL_UP && !mb->is_command_or_control_pressed()) {
|
||||
if (mb->is_shift_pressed()) {
|
||||
h_scroll->set_value(h_scroll->get_value() - (100 * mb->get_factor()));
|
||||
queue_accessibility_update();
|
||||
} else if (mb->is_alt_pressed()) {
|
||||
// Scroll 5 times as fast as normal (like in Visual Studio Code).
|
||||
_scroll_up(15 * mb->get_factor(), true);
|
||||
@ -1875,6 +2069,7 @@ void TextEdit::gui_input(const Ref<InputEvent> &p_gui_input) {
|
||||
if (mb->get_button_index() == MouseButton::WHEEL_DOWN && !mb->is_command_or_control_pressed()) {
|
||||
if (mb->is_shift_pressed()) {
|
||||
h_scroll->set_value(h_scroll->get_value() + (100 * mb->get_factor()));
|
||||
queue_accessibility_update();
|
||||
} else if (mb->is_alt_pressed()) {
|
||||
// Scroll 5 times as fast as normal (like in Visual Studio Code).
|
||||
_scroll_down(15 * mb->get_factor(), true);
|
||||
@ -1885,9 +2080,11 @@ void TextEdit::gui_input(const Ref<InputEvent> &p_gui_input) {
|
||||
}
|
||||
if (mb->get_button_index() == MouseButton::WHEEL_LEFT) {
|
||||
h_scroll->set_value(h_scroll->get_value() - (100 * mb->get_factor()));
|
||||
queue_accessibility_update();
|
||||
}
|
||||
if (mb->get_button_index() == MouseButton::WHEEL_RIGHT) {
|
||||
h_scroll->set_value(h_scroll->get_value() + (100 * mb->get_factor()));
|
||||
queue_accessibility_update();
|
||||
}
|
||||
|
||||
if (mb->get_button_index() == MouseButton::LEFT) {
|
||||
@ -1961,6 +2158,8 @@ void TextEdit::gui_input(const Ref<InputEvent> &p_gui_input) {
|
||||
return;
|
||||
}
|
||||
|
||||
queue_accessibility_update();
|
||||
|
||||
last_dblclk = 0;
|
||||
} else if (!mb->is_shift_pressed()) {
|
||||
if (drag_and_drop_selection_enabled && mouse_over_selection_caret >= 0) {
|
||||
@ -2005,6 +2204,7 @@ void TextEdit::gui_input(const Ref<InputEvent> &p_gui_input) {
|
||||
last_dblclk = OS::get_singleton()->get_ticks_msec();
|
||||
last_dblclk_pos = mb->get_position();
|
||||
}
|
||||
queue_accessibility_update();
|
||||
queue_redraw();
|
||||
}
|
||||
|
||||
@ -2086,6 +2286,7 @@ void TextEdit::gui_input(const Ref<InputEvent> &p_gui_input) {
|
||||
if (v_scroll->get_value() != prev_v_scroll || h_scroll->get_value() != prev_h_scroll) {
|
||||
accept_event(); // Accept event if scroll changed.
|
||||
}
|
||||
queue_accessibility_update();
|
||||
|
||||
return;
|
||||
}
|
||||
@ -2417,8 +2618,15 @@ void TextEdit::gui_input(const Ref<InputEvent> &p_gui_input) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Toggle Tab mode.
|
||||
if (k->is_action("ui_focus_mode", true)) {
|
||||
tab_input_mode = !tab_input_mode;
|
||||
accept_event();
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle tab as it has no set unicode value.
|
||||
if (k->is_action("ui_text_indent", true)) {
|
||||
if (tab_input_mode && k->is_action("ui_text_indent", true)) {
|
||||
if (editable) {
|
||||
insert_text_at_caret("\t");
|
||||
}
|
||||
@ -2996,6 +3204,7 @@ void TextEdit::_update_caches() {
|
||||
syntax_highlighter->set_text_edit(this);
|
||||
}
|
||||
_clear_syntax_highlighting_cache();
|
||||
queue_accessibility_update();
|
||||
}
|
||||
|
||||
void TextEdit::_close_ime_window() {
|
||||
@ -3039,6 +3248,7 @@ void TextEdit::_update_ime_text() {
|
||||
}
|
||||
}
|
||||
_clear_syntax_highlighting_cache();
|
||||
queue_accessibility_update();
|
||||
queue_redraw();
|
||||
}
|
||||
|
||||
@ -3111,7 +3321,9 @@ bool TextEdit::can_drop_data(const Point2 &p_point, const Variant &p_data) const
|
||||
void TextEdit::drop_data(const Point2 &p_point, const Variant &p_data) {
|
||||
Control::drop_data(p_point, p_data);
|
||||
|
||||
if (p_data.is_string() && is_editable()) {
|
||||
if (p_point == Vector2(INFINITY, INFINITY)) {
|
||||
insert_text_at_caret(p_data);
|
||||
} else if (p_data.is_string() && is_editable()) {
|
||||
Point2i pos = get_line_column_at_pos(get_local_mouse_pos());
|
||||
int drop_at_line = pos.y;
|
||||
int drop_at_column = pos.x;
|
||||
@ -3215,6 +3427,7 @@ String TextEdit::get_tooltip(const Point2 &p_pos) const {
|
||||
|
||||
void TextEdit::set_tooltip_request_func(const Callable &p_tooltip_callback) {
|
||||
tooltip_callback = p_tooltip_callback;
|
||||
queue_accessibility_update();
|
||||
}
|
||||
|
||||
/* Text */
|
||||
@ -3261,7 +3474,7 @@ void TextEdit::set_editable(bool p_editable) {
|
||||
}
|
||||
|
||||
editable = p_editable;
|
||||
|
||||
queue_accessibility_update();
|
||||
queue_redraw();
|
||||
}
|
||||
|
||||
@ -3292,6 +3505,7 @@ void TextEdit::set_text_direction(Control::TextDirection p_text_direction) {
|
||||
menu_dir->set_item_checked(menu_dir->get_item_index(MENU_DIR_LTR), text_direction == TEXT_DIRECTION_LTR);
|
||||
menu_dir->set_item_checked(menu_dir->get_item_index(MENU_DIR_RTL), text_direction == TEXT_DIRECTION_RTL);
|
||||
}
|
||||
queue_accessibility_update();
|
||||
queue_redraw();
|
||||
}
|
||||
}
|
||||
@ -3312,6 +3526,7 @@ void TextEdit::set_language(const String &p_language) {
|
||||
text.set_direction_and_language(dir, (!language.is_empty()) ? language : TranslationServer::get_singleton()->get_tool_locale());
|
||||
text.invalidate_all();
|
||||
_update_placeholder();
|
||||
queue_accessibility_update();
|
||||
queue_redraw();
|
||||
}
|
||||
}
|
||||
@ -3326,6 +3541,7 @@ void TextEdit::set_structured_text_bidi_override(TextServer::StructuredTextParse
|
||||
for (int i = 0; i < text.size(); i++) {
|
||||
text.set(i, text[i], structured_text_parser(st_parser, st_args, text[i]));
|
||||
}
|
||||
queue_accessibility_update();
|
||||
queue_redraw();
|
||||
}
|
||||
}
|
||||
@ -3343,6 +3559,7 @@ void TextEdit::set_structured_text_bidi_override_options(Array p_args) {
|
||||
for (int i = 0; i < text.size(); i++) {
|
||||
text.set(i, text[i], structured_text_parser(st_parser, st_args, text[i]));
|
||||
}
|
||||
queue_accessibility_update();
|
||||
queue_redraw();
|
||||
}
|
||||
|
||||
@ -3358,6 +3575,7 @@ void TextEdit::set_tab_size(const int p_size) {
|
||||
text.set_tab_size(p_size);
|
||||
text.invalidate_all_lines();
|
||||
_update_placeholder();
|
||||
queue_accessibility_update();
|
||||
queue_redraw();
|
||||
}
|
||||
|
||||
@ -3379,6 +3597,14 @@ bool TextEdit::is_indent_wrapped_lines() const {
|
||||
return text.is_indent_wrapped_lines();
|
||||
}
|
||||
|
||||
void TextEdit::set_tab_input_mode(bool p_enabled) {
|
||||
tab_input_mode = p_enabled;
|
||||
}
|
||||
|
||||
bool TextEdit::get_tab_input_mode() const {
|
||||
return tab_input_mode;
|
||||
}
|
||||
|
||||
// User controls
|
||||
void TextEdit::set_overtype_mode_enabled(bool p_enabled) {
|
||||
if (overtype_mode == p_enabled) {
|
||||
@ -3508,7 +3734,7 @@ void TextEdit::set_text(const String &p_text) {
|
||||
|
||||
set_caret_line(0);
|
||||
set_caret_column(0);
|
||||
|
||||
queue_accessibility_update();
|
||||
queue_redraw();
|
||||
setting_text = false;
|
||||
emit_signal(SNAME("text_set"));
|
||||
@ -3537,6 +3763,7 @@ void TextEdit::set_placeholder(const String &p_text) {
|
||||
|
||||
placeholder_text = p_text;
|
||||
_update_placeholder();
|
||||
queue_accessibility_update();
|
||||
queue_redraw();
|
||||
}
|
||||
|
||||
@ -3773,6 +4000,9 @@ void TextEdit::remove_line_at(int p_line, bool p_move_carets_down) {
|
||||
_offset_carets_after(next_line, next_column, from_line, from_column);
|
||||
end_multicaret_edit();
|
||||
end_complex_operation();
|
||||
|
||||
queue_accessibility_update();
|
||||
queue_redraw();
|
||||
}
|
||||
|
||||
void TextEdit::insert_text_at_caret(const String &p_text, int p_caret) {
|
||||
@ -4153,6 +4383,7 @@ void TextEdit::start_action(EditAction p_action) {
|
||||
void TextEdit::end_action() {
|
||||
if (current_action != EditAction::ACTION_NONE) {
|
||||
pending_action_end = true;
|
||||
queue_accessibility_update();
|
||||
}
|
||||
}
|
||||
|
||||
@ -4172,6 +4403,8 @@ void TextEdit::begin_complex_operation() {
|
||||
void TextEdit::end_complex_operation() {
|
||||
_push_current_op();
|
||||
|
||||
queue_accessibility_update();
|
||||
|
||||
complex_operation_count = MAX(complex_operation_count - 1, 0);
|
||||
if (complex_operation_count > 0) {
|
||||
return;
|
||||
@ -4264,6 +4497,7 @@ void TextEdit::undo() {
|
||||
_selection_changed();
|
||||
}
|
||||
adjust_viewport_to_caret();
|
||||
queue_accessibility_update();
|
||||
}
|
||||
|
||||
void TextEdit::redo() {
|
||||
@ -4320,6 +4554,7 @@ void TextEdit::redo() {
|
||||
_selection_changed();
|
||||
}
|
||||
adjust_viewport_to_caret();
|
||||
queue_accessibility_update();
|
||||
}
|
||||
|
||||
void TextEdit::clear_undo_history() {
|
||||
@ -4591,7 +4826,7 @@ Rect2i TextEdit::get_rect_at_line_column(int p_line, int p_column) const {
|
||||
ERR_FAIL_COND_V(p_column < 0, Rect2i(-1, -1, 0, 0));
|
||||
ERR_FAIL_COND_V(p_column > text[p_line].length(), Rect2i(-1, -1, 0, 0));
|
||||
|
||||
if (text.size() == 1 && text[0].length() == 0) {
|
||||
if (text.size() == 1 && text[0].is_empty()) {
|
||||
// The TextEdit is empty.
|
||||
return Rect2i();
|
||||
}
|
||||
@ -4841,6 +5076,7 @@ void TextEdit::remove_secondary_carets() {
|
||||
if (drag_caret_index >= 0) {
|
||||
drag_caret_index = -1;
|
||||
}
|
||||
queue_accessibility_update();
|
||||
}
|
||||
|
||||
int TextEdit::get_caret_count() const {
|
||||
@ -5262,6 +5498,7 @@ void TextEdit::set_caret_line(int p_line, bool p_adjust_viewport, bool p_can_be_
|
||||
if (caret_moved) {
|
||||
_caret_changed(p_caret);
|
||||
}
|
||||
queue_accessibility_update();
|
||||
}
|
||||
|
||||
int TextEdit::get_caret_line(int p_caret) const {
|
||||
@ -5296,6 +5533,7 @@ void TextEdit::set_caret_column(int p_column, bool p_adjust_viewport, int p_care
|
||||
if (caret_moved) {
|
||||
_caret_changed(p_caret);
|
||||
}
|
||||
queue_accessibility_update();
|
||||
}
|
||||
|
||||
int TextEdit::get_caret_column(int p_caret) const {
|
||||
@ -5384,7 +5622,7 @@ void TextEdit::select_all() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (text.size() == 1 && text[0].length() == 0) {
|
||||
if (text.size() == 1 && text[0].is_empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -5401,7 +5639,7 @@ void TextEdit::select_word_under_caret(int p_caret) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (text.size() == 1 && text[0].length() == 0) {
|
||||
if (text.size() == 1 && text[0].is_empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -5446,7 +5684,7 @@ void TextEdit::add_selection_for_next_occurrence() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (text.size() == 1 && text[0].length() == 0) {
|
||||
if (text.size() == 1 && text[0].is_empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -5489,7 +5727,7 @@ void TextEdit::skip_selection_for_next_occurrence() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (text.size() == 1 && text[0].length() == 0) {
|
||||
if (text.size() == 1 && text[0].is_empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -5558,6 +5796,9 @@ void TextEdit::select(int p_origin_line, int p_origin_column, int p_caret_line,
|
||||
if (had_selection != activate) {
|
||||
_selection_changed(p_caret);
|
||||
}
|
||||
|
||||
queue_accessibility_update();
|
||||
queue_redraw();
|
||||
}
|
||||
|
||||
bool TextEdit::has_selection(int p_caret) const {
|
||||
@ -5802,6 +6043,9 @@ void TextEdit::deselect(int p_caret) {
|
||||
if (selection_changed) {
|
||||
_selection_changed(p_caret);
|
||||
}
|
||||
|
||||
queue_accessibility_update();
|
||||
queue_redraw();
|
||||
}
|
||||
|
||||
void TextEdit::delete_selection(int p_caret) {
|
||||
@ -5843,6 +6087,7 @@ void TextEdit::set_line_wrapping_mode(LineWrappingMode p_wrapping_mode) {
|
||||
if (line_wrapping_mode != p_wrapping_mode) {
|
||||
line_wrapping_mode = p_wrapping_mode;
|
||||
_update_wrap_at_column(true);
|
||||
queue_accessibility_update();
|
||||
queue_redraw();
|
||||
}
|
||||
}
|
||||
@ -5859,6 +6104,7 @@ void TextEdit::set_autowrap_mode(TextServer::AutowrapMode p_mode) {
|
||||
autowrap_mode = p_mode;
|
||||
if (get_line_wrapping_mode() != LineWrappingMode::LINE_WRAPPING_NONE) {
|
||||
_update_wrap_at_column(true);
|
||||
queue_accessibility_update();
|
||||
queue_redraw();
|
||||
}
|
||||
}
|
||||
@ -5964,6 +6210,7 @@ void TextEdit::set_v_scroll(double p_scroll) {
|
||||
if (p_scroll >= max_v_scroll - 1.0) {
|
||||
_scroll_moved(v_scroll->get_value());
|
||||
}
|
||||
queue_accessibility_update();
|
||||
}
|
||||
|
||||
double TextEdit::get_v_scroll() const {
|
||||
@ -5975,6 +6222,7 @@ void TextEdit::set_h_scroll(int p_scroll) {
|
||||
p_scroll = 0;
|
||||
}
|
||||
h_scroll->set_value(p_scroll);
|
||||
queue_accessibility_update();
|
||||
}
|
||||
|
||||
int TextEdit::get_h_scroll() const {
|
||||
@ -6550,6 +6798,7 @@ void TextEdit::set_draw_control_chars(bool p_enabled) {
|
||||
text.set_draw_control_chars(draw_control_chars);
|
||||
text.invalidate_font();
|
||||
_update_placeholder();
|
||||
queue_accessibility_update();
|
||||
queue_redraw();
|
||||
}
|
||||
}
|
||||
@ -6615,6 +6864,9 @@ void TextEdit::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_indent_wrapped_lines", "enabled"), &TextEdit::set_indent_wrapped_lines);
|
||||
ClassDB::bind_method(D_METHOD("is_indent_wrapped_lines"), &TextEdit::is_indent_wrapped_lines);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_tab_input_mode", "enabled"), &TextEdit::set_tab_input_mode);
|
||||
ClassDB::bind_method(D_METHOD("get_tab_input_mode"), &TextEdit::get_tab_input_mode);
|
||||
|
||||
// User controls
|
||||
ClassDB::bind_method(D_METHOD("set_overtype_mode_enabled", "enabled"), &TextEdit::set_overtype_mode_enabled);
|
||||
ClassDB::bind_method(D_METHOD("is_overtype_mode_enabled"), &TextEdit::is_overtype_mode_enabled);
|
||||
@ -7037,6 +7289,7 @@ void TextEdit::_bind_methods() {
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "wrap_mode", PROPERTY_HINT_ENUM, "None,Boundary"), "set_line_wrapping_mode", "get_line_wrapping_mode");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "autowrap_mode", PROPERTY_HINT_ENUM, "Arbitrary:1,Word:2,Word (Smart):3"), "set_autowrap_mode", "get_autowrap_mode");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "indent_wrapped_lines"), "set_indent_wrapped_lines", "is_indent_wrapped_lines");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "tab_input_mode"), "set_tab_input_mode", "get_tab_input_mode");
|
||||
|
||||
ADD_GROUP("Scroll", "scroll_");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "scroll_smooth"), "set_smooth_scroll_enabled", "is_smooth_scroll_enabled");
|
||||
@ -7147,6 +7400,7 @@ void TextEdit::_set_hiding_enabled(bool p_enabled) {
|
||||
_unhide_all_lines();
|
||||
}
|
||||
hiding_enabled = p_enabled;
|
||||
queue_accessibility_update();
|
||||
queue_redraw();
|
||||
}
|
||||
|
||||
@ -7164,6 +7418,7 @@ void TextEdit::_unhide_all_lines() {
|
||||
text.set_hidden(i, false);
|
||||
}
|
||||
_update_scrollbars();
|
||||
queue_accessibility_update();
|
||||
queue_redraw();
|
||||
}
|
||||
|
||||
@ -7181,6 +7436,7 @@ void TextEdit::_set_line_as_hidden(int p_line, bool p_hidden) {
|
||||
if (_is_hiding_enabled() || !p_hidden) {
|
||||
text.set_hidden(p_line, p_hidden);
|
||||
}
|
||||
queue_accessibility_update();
|
||||
queue_redraw();
|
||||
}
|
||||
|
||||
@ -7833,6 +8089,7 @@ void TextEdit::_selection_changed(int p_caret) {
|
||||
}
|
||||
|
||||
_cancel_drag_and_drop_text();
|
||||
queue_accessibility_update();
|
||||
queue_redraw();
|
||||
}
|
||||
|
||||
@ -8035,6 +8292,7 @@ void TextEdit::_update_wrap_at_column(bool p_force) {
|
||||
first_visible_line_wrap_ofs = 0;
|
||||
}
|
||||
set_line_as_first_visible(first_visible_line, first_visible_line_wrap_ofs);
|
||||
queue_accessibility_update();
|
||||
}
|
||||
|
||||
/* Viewport. */
|
||||
@ -8151,6 +8409,7 @@ void TextEdit::_scroll_moved(double p_to_val) {
|
||||
first_visible_line = n_line;
|
||||
first_visible_line_wrap_ofs = wi;
|
||||
}
|
||||
queue_accessibility_update();
|
||||
queue_redraw();
|
||||
}
|
||||
|
||||
@ -8185,6 +8444,7 @@ void TextEdit::_scroll_up(real_t p_delta, bool p_animate) {
|
||||
}
|
||||
if (!p_animate || Math::abs(target_v_scroll - v_scroll->get_value()) < 1.0) {
|
||||
v_scroll->set_value(target_v_scroll);
|
||||
queue_accessibility_update();
|
||||
} else {
|
||||
scrolling = true;
|
||||
set_physics_process_internal(true);
|
||||
@ -8213,6 +8473,7 @@ void TextEdit::_scroll_down(real_t p_delta, bool p_animate) {
|
||||
}
|
||||
if (!p_animate || Math::abs(target_v_scroll - v_scroll->get_value()) < 1.0) {
|
||||
v_scroll->set_value(target_v_scroll);
|
||||
queue_accessibility_update();
|
||||
} else {
|
||||
scrolling = true;
|
||||
set_physics_process_internal(true);
|
||||
@ -8326,6 +8587,8 @@ void TextEdit::_adjust_viewport_to_caret_horizontally(int p_caret, bool p_maximi
|
||||
}
|
||||
|
||||
h_scroll->set_value(first_visible_col);
|
||||
|
||||
queue_accessibility_update();
|
||||
queue_redraw();
|
||||
}
|
||||
|
||||
@ -8418,6 +8681,7 @@ void TextEdit::_update_gutter_width() {
|
||||
if (get_viewport()) {
|
||||
hovered_gutter = _get_hovered_gutter(get_local_mouse_position());
|
||||
}
|
||||
queue_accessibility_update();
|
||||
queue_redraw();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user