-fix TextEdit shift-click functionality past begin and end of selection (#1004)
This commit is contained in:
parent
fbfb87ec4f
commit
8a28af024e
2 changed files with 2751 additions and 2714 deletions
|
@ -26,7 +26,7 @@
|
||||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||||
/*************************************************************************/
|
/*************************************************************************/
|
||||||
/*****f********************************************/
|
/*****f********************************************/
|
||||||
/* text_edit.cpp */
|
/* text_edit.cpp */
|
||||||
/*************************************************/
|
/*************************************************/
|
||||||
/* This file is part of: */
|
/* This file is part of: */
|
||||||
|
@ -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 {
|
||||||
|
|
||||||
|
@ -1963,7 +1999,7 @@ void TextEdit::_input_event(const InputEvent& p_input_event) {
|
||||||
|
|
||||||
if (scancode_handled)
|
if (scancode_handled)
|
||||||
accept_event();
|
accept_event();
|
||||||
/*
|
/*
|
||||||
if (!scancode_handled && !k.mod.command && !k.mod.alt) {
|
if (!scancode_handled && !k.mod.command && !k.mod.alt) {
|
||||||
|
|
||||||
if (k.unicode>=32) {
|
if (k.unicode>=32) {
|
||||||
|
@ -2321,7 +2357,7 @@ void TextEdit::adjust_viewport_to_cursor() {
|
||||||
cursor.x_ofs=cursor_x;
|
cursor.x_ofs=cursor_x;
|
||||||
|
|
||||||
update();
|
update();
|
||||||
/*
|
/*
|
||||||
get_range()->set_max(text.size());
|
get_range()->set_max(text.size());
|
||||||
|
|
||||||
get_range()->set_page(get_visible_rows());
|
get_range()->set_page(get_visible_rows());
|
||||||
|
@ -3298,7 +3334,7 @@ void TextEdit::_update_completion_candidates() {
|
||||||
if (completion_options.size()==1) {
|
if (completion_options.size()==1) {
|
||||||
//one option to complete, just complete it automagically
|
//one option to complete, just complete it automagically
|
||||||
_confirm_completion();
|
_confirm_completion();
|
||||||
// insert_text_at_cursor(completion_options[0].substr(s.length(),completion_options[0].length()-s.length()));
|
// insert_text_at_cursor(completion_options[0].substr(s.length(),completion_options[0].length()-s.length()));
|
||||||
_cancel_completion();
|
_cancel_completion();
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -3338,7 +3374,7 @@ void TextEdit::code_complete(const Vector<String> &p_strings) {
|
||||||
completion_current="";
|
completion_current="";
|
||||||
completion_index=0;
|
completion_index=0;
|
||||||
_update_completion_candidates();
|
_update_completion_candidates();
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -3424,7 +3460,7 @@ void TextEdit::_bind_methods() {
|
||||||
BIND_CONSTANT( SEARCH_WHOLE_WORDS );
|
BIND_CONSTANT( SEARCH_WHOLE_WORDS );
|
||||||
BIND_CONSTANT( SEARCH_BACKWARDS );
|
BIND_CONSTANT( SEARCH_BACKWARDS );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
ObjectTypeDB::bind_method(_MD("delete_char"),&TextEdit::delete_char);
|
ObjectTypeDB::bind_method(_MD("delete_char"),&TextEdit::delete_char);
|
||||||
ObjectTypeDB::bind_method(_MD("delete_line"),&TextEdit::delete_line);
|
ObjectTypeDB::bind_method(_MD("delete_line"),&TextEdit::delete_line);
|
||||||
*/
|
*/
|
||||||
|
@ -3497,8 +3533,8 @@ TextEdit::TextEdit() {
|
||||||
tab_size=4;
|
tab_size=4;
|
||||||
text.set_tab_size(tab_size);
|
text.set_tab_size(tab_size);
|
||||||
text.clear();
|
text.clear();
|
||||||
// text.insert(1,"Mongolia..");
|
// text.insert(1,"Mongolia..");
|
||||||
// text.insert(2,"PAIS GENEROSO!!");
|
// text.insert(2,"PAIS GENEROSO!!");
|
||||||
text.set_color_regions(&color_regions);
|
text.set_color_regions(&color_regions);
|
||||||
|
|
||||||
h_scroll = memnew( HScrollBar );
|
h_scroll = memnew( HScrollBar );
|
||||||
|
|
|
@ -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;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue