summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
Diffstat (limited to 'scene')
-rw-r--r--scene/gui/line_edit.cpp33
-rw-r--r--scene/gui/line_edit.h5
-rw-r--r--scene/gui/text_edit.cpp10
-rw-r--r--scene/gui/text_edit.h2
4 files changed, 19 insertions, 31 deletions
diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp
index 85ae6d6241..cebbb2193d 100644
--- a/scene/gui/line_edit.cpp
+++ b/scene/gui/line_edit.cpp
@@ -85,7 +85,7 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
if ((cursor_pos < selection.begin) || (cursor_pos > selection.end) || !selection.enabled) {
- selection_clear();
+ deselect();
selection.cursor_start = cursor_pos;
selection.creating = true;
} else if (selection.enabled) {
@@ -99,7 +99,7 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
} else {
if ((!selection.creating) && (!selection.doubleclick)) {
- selection_clear();
+ deselect();
}
selection.creating = false;
selection.doubleclick = false;
@@ -175,7 +175,7 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
if (editable) {
- selection_clear();
+ deselect();
text = text.substr(cursor_pos, text.length() - cursor_pos);
Ref<Font> font = get_font("font");
@@ -204,7 +204,7 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
if (editable) {
- selection_clear();
+ deselect();
text = text.substr(0, cursor_pos);
_text_changed();
}
@@ -827,7 +827,7 @@ void LineEdit::shift_selection_check_pre(bool p_shift) {
selection.cursor_start = cursor_pos;
}
if (!p_shift)
- selection_clear();
+ deselect();
}
void LineEdit::shift_selection_check_post(bool p_shift) {
@@ -880,13 +880,6 @@ void LineEdit::set_cursor_at_pixel_pos(int p_x) {
}
set_cursor_position(ofs);
-
- /*
- int new_cursor_pos=p_x;
- int charwidth=draw_area->get_font_char_width(' ',0);
- new_cursor_pos=( ( (new_cursor_pos-2)+ (charwidth/2) ) /charwidth );
- if (new_cursor_pos>(int)text.length()) new_cursor_pos=text.length();
- set_cursor_position(window_pos+new_cursor_pos); */
}
bool LineEdit::cursor_get_blink_enabled() const {
@@ -941,11 +934,6 @@ void LineEdit::delete_char() {
set_cursor_position(get_cursor_position() - 1);
- if (cursor_pos == window_pos) {
-
- //set_window_pos(cursor_pos-get_window_length());
- }
-
_text_changed();
}
@@ -1143,7 +1131,7 @@ Size2 LineEdit::get_minimum_size() const {
/* selection */
-void LineEdit::selection_clear() {
+void LineEdit::deselect() {
selection.begin = 0;
selection.end = 0;
@@ -1159,7 +1147,7 @@ void LineEdit::selection_delete() {
if (selection.enabled)
delete_text(selection.begin, selection.end);
- selection_clear();
+ deselect();
}
void LineEdit::set_max_length(int p_max_length) {
@@ -1224,7 +1212,7 @@ bool LineEdit::is_secret() const {
void LineEdit::select(int p_from, int p_to) {
if (p_from == 0 && p_to == 0) {
- selection_clear();
+ deselect();
return;
}
@@ -1383,7 +1371,9 @@ void LineEdit::_bind_methods() {
ClassDB::bind_method(D_METHOD("_gui_input"), &LineEdit::_gui_input);
ClassDB::bind_method(D_METHOD("clear"), &LineEdit::clear);
+ ClassDB::bind_method(D_METHOD("select", "from", "to"), &LineEdit::select, DEFVAL(0), DEFVAL(-1));
ClassDB::bind_method(D_METHOD("select_all"), &LineEdit::select_all);
+ ClassDB::bind_method(D_METHOD("deselect"), &LineEdit::deselect);
ClassDB::bind_method(D_METHOD("set_text", "text"), &LineEdit::set_text);
ClassDB::bind_method(D_METHOD("get_text"), &LineEdit::get_text);
ClassDB::bind_method(D_METHOD("set_placeholder", "text"), &LineEdit::set_placeholder);
@@ -1405,7 +1395,6 @@ void LineEdit::_bind_methods() {
ClassDB::bind_method(D_METHOD("is_editable"), &LineEdit::is_editable);
ClassDB::bind_method(D_METHOD("set_secret", "enabled"), &LineEdit::set_secret);
ClassDB::bind_method(D_METHOD("is_secret"), &LineEdit::is_secret);
- ClassDB::bind_method(D_METHOD("select", "from", "to"), &LineEdit::select, DEFVAL(0), DEFVAL(-1));
ClassDB::bind_method(D_METHOD("menu_option", "option"), &LineEdit::menu_option);
ClassDB::bind_method(D_METHOD("get_menu"), &LineEdit::get_menu);
ClassDB::bind_method(D_METHOD("set_context_menu_enabled", "enable"), &LineEdit::set_context_menu_enabled);
@@ -1457,7 +1446,7 @@ LineEdit::LineEdit() {
pass = false;
placeholder_alpha = 0.6;
- selection_clear();
+ deselect();
set_focus_mode(FOCUS_ALL);
editable = true;
set_default_cursor_shape(CURSOR_IBEAM);
diff --git a/scene/gui/line_edit.h b/scene/gui/line_edit.h
index c3a299c2f5..5ca4ca15df 100644
--- a/scene/gui/line_edit.h
+++ b/scene/gui/line_edit.h
@@ -119,7 +119,6 @@ private:
void shift_selection_check_pre(bool);
void shift_selection_check_post(bool);
- void selection_clear();
void selection_fill_at_cursor();
void selection_delete();
void set_window_pos(int p_pos);
@@ -155,7 +154,9 @@ public:
bool is_context_menu_enabled();
PopupMenu *get_menu() const;
+ void select(int p_from = 0, int p_to = -1);
void select_all();
+ void deselect();
void delete_char();
void delete_text(int p_from_column, int p_to_column);
@@ -190,8 +191,6 @@ public:
void set_secret(bool p_secret);
bool is_secret() const;
- void select(int p_from = 0, int p_to = -1);
-
virtual Size2 get_minimum_size() const;
void set_expand_to_text_length(bool p_enabled);
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index 83aee5ca30..07f1bdf8e5 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -4084,7 +4084,7 @@ void TextEdit::cut() {
backspace_at_cursor();
update();
cursor_set_line(cursor.line + 1);
- cut_copy_line = true;
+ cut_copy_line = clipboard;
} else {
@@ -4098,7 +4098,7 @@ void TextEdit::cut() {
selection.active = false;
selection.selecting_mode = Selection::MODE_NONE;
update();
- cut_copy_line = false;
+ cut_copy_line = "";
}
}
@@ -4107,11 +4107,11 @@ void TextEdit::copy() {
if (!selection.active) {
String clipboard = _base_get_text(cursor.line, 0, cursor.line, text[cursor.line].length());
OS::get_singleton()->set_clipboard(clipboard);
- cut_copy_line = true;
+ cut_copy_line = clipboard;
} else {
String clipboard = _base_get_text(selection.from_line, selection.from_column, selection.to_line, selection.to_column);
OS::get_singleton()->set_clipboard(clipboard);
- cut_copy_line = false;
+ cut_copy_line = "";
}
}
@@ -4127,7 +4127,7 @@ void TextEdit::paste() {
cursor_set_line(selection.from_line);
cursor_set_column(selection.from_column);
- } else if (cut_copy_line) {
+ } else if (!cut_copy_line.empty() && cut_copy_line == clipboard) {
cursor_set_column(0);
String ins = "\n";
diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h
index edef28cc25..836d5c7388 100644
--- a/scene/gui/text_edit.h
+++ b/scene/gui/text_edit.h
@@ -270,7 +270,7 @@ class TextEdit : public Control {
bool brace_matching_enabled;
bool highlight_current_line;
bool auto_indent;
- bool cut_copy_line;
+ String cut_copy_line;
bool insert_mode;
bool select_identifiers_enabled;