Uncommenting a selection was not updating the selection.
Also adds uncomment lines(ctrl+u) where # is not in first place
This commit is contained in:
parent
db55d8a4b6
commit
5cb66b2776
|
@ -3119,16 +3119,14 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
|
|||
if (selection.active) {
|
||||
int ini = selection.from_line;
|
||||
int end = selection.to_line;
|
||||
|
||||
for (int i = ini; i <= end; i++) {
|
||||
if (get_line(i).begins_with("#"))
|
||||
_remove_text(i, 0, i, 1);
|
||||
_uncomment_line(i);
|
||||
}
|
||||
} else {
|
||||
if (get_line(cursor.line).begins_with("#")) {
|
||||
_remove_text(cursor.line, 0, cursor.line, 1);
|
||||
if (cursor.column >= get_line(cursor.line).length()) {
|
||||
cursor.column = MAX(0, get_line(cursor.line).length() - 1);
|
||||
}
|
||||
_uncomment_line(cursor.line);
|
||||
if (cursor.column >= get_line(cursor.line).length()) {
|
||||
cursor.column = MAX(0, get_line(cursor.line).length() - 1);
|
||||
}
|
||||
}
|
||||
update();
|
||||
|
@ -3208,6 +3206,24 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
|
|||
}
|
||||
}
|
||||
|
||||
void TextEdit::_uncomment_line(int p_line) {
|
||||
String line_text = get_line(p_line);
|
||||
for (int i = 0; i < line_text.length(); i++) {
|
||||
if (line_text[i] == '#') {
|
||||
_remove_text(p_line, i, p_line, i + 1);
|
||||
if (p_line == selection.to_line && selection.to_column > line_text.length() - 1) {
|
||||
selection.to_column -= 1;
|
||||
if (selection.to_column >= selection.from_column) {
|
||||
selection.active = false;
|
||||
}
|
||||
}
|
||||
return;
|
||||
} else if (line_text[i] != '\t' && line_text[i] != ' ') {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TextEdit::_scroll_up(real_t p_delta) {
|
||||
|
||||
if (scrolling && smooth_scroll_enabled && SGN(target_v_scroll - v_scroll->get_value()) != SGN(-p_delta))
|
||||
|
@ -5910,6 +5926,9 @@ void TextEdit::set_line(int line, String new_text) {
|
|||
if (cursor.line == line) {
|
||||
cursor.column = MIN(cursor.column, new_text.length());
|
||||
}
|
||||
if (is_selection_active() && line == selection.to_line && selection.to_column > text[line].length()) {
|
||||
selection.to_column = text[line].length();
|
||||
}
|
||||
}
|
||||
|
||||
void TextEdit::insert_at(const String &p_text, int at) {
|
||||
|
|
|
@ -373,6 +373,7 @@ private:
|
|||
void _update_selection_mode_word();
|
||||
void _update_selection_mode_line();
|
||||
|
||||
void _uncomment_line(int p_line);
|
||||
void _scroll_up(real_t p_delta);
|
||||
void _scroll_down(real_t p_delta);
|
||||
|
||||
|
|
Loading…
Reference in New Issue