-fix TextEdit shift-click functionality past begin and end of selection (#1004)

This commit is contained in:
Juan Linietsky 2015-01-02 15:08:40 -03:00
parent fbfb87ec4f
commit 8a28af024e
2 changed files with 2751 additions and 2714 deletions

View file

@ -1152,19 +1152,55 @@ void TextEdit::_input_event(const InputEvent& p_input_event) {
if (mb.mod.shift && (cursor.column!=prev_col || cursor.line!=prev_line)) { if (mb.mod.shift && (cursor.column!=prev_col || cursor.line!=prev_line)) {
if (!selection.active) {
selection.active=true; selection.active=true;
selection.selecting_mode=Selection::MODE_POINTER; selection.selecting_mode=Selection::MODE_POINTER;
selection.from_column=prev_col; selection.from_column=prev_col;
selection.from_line=prev_line; selection.from_line=prev_line;
selection.to_column=cursor.column; selection.to_column=cursor.column;
selection.to_line=cursor.line; selection.to_line=cursor.line;
if (selection.from_column>selection.to_column) {
if (selection.from_line>selection.to_line || (selection.from_line==selection.to_line && selection.from_column>selection.to_column)) {
SWAP(selection.from_column,selection.to_column); SWAP(selection.from_column,selection.to_column);
SWAP(selection.from_line,selection.to_line); SWAP(selection.from_line,selection.to_line);
selection.shiftclick_left=false;
} else {
selection.shiftclick_left=true;
} }
selection.selecting_line=prev_line; selection.selecting_line=prev_line;
selection.selecting_column=prev_col; selection.selecting_column=prev_col;
update(); update();
} else {
if (cursor.line<selection.from_line || (cursor.line==selection.from_line && cursor.column<=selection.from_column)) {
selection.from_column=cursor.column;
selection.from_line=cursor.line;
} else if (cursor.line>selection.to_line || (cursor.line==selection.to_line && cursor.column>=selection.to_column)) {
selection.to_column=cursor.column;
selection.to_line=cursor.line;
} else if (!selection.shiftclick_left) {
selection.from_column=cursor.column;
selection.from_line=cursor.line;
} else {
selection.to_column=cursor.column;
selection.to_line=cursor.line;
}
if (selection.from_line>selection.to_line || (selection.from_line==selection.to_line && selection.from_column>selection.to_column)) {
SWAP(selection.from_column,selection.to_column);
SWAP(selection.from_line,selection.to_line);
}
update();
}
} else { } else {

View file

@ -63,6 +63,7 @@ class TextEdit : public Control {
int from_line,from_column; int from_line,from_column;
int to_line,to_column; int to_line,to_column;
bool shiftclick_left;
} selection; } selection;