summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaulb23 <p_batty@hotmail.co.uk>2016-04-27 18:32:14 +0100
committerPaulb23 <p_batty@hotmail.co.uk>2016-04-27 18:32:14 +0100
commit54244e0e1d37c03d86b1628df062b23c09a79c43 (patch)
treea1eda1ddd2140d528655328a6db95dfae3004f98
parent87aa1282285fe4c71caa82740b7f1d6ddb5643b6 (diff)
Added scroll lines, issue 4243
-rw-r--r--scene/gui/text_edit.cpp54
-rw-r--r--scene/gui/text_edit.h3
2 files changed, 55 insertions, 2 deletions
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index f7461a736c..41d546c6f7 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -2057,7 +2057,17 @@ void TextEdit::_input_event(const InputEvent& p_input_event) {
scancode_handled=false;
break;
}
-#ifdef APPLE_STYLE_KEYS
+#ifndef APPLE_STYLE_KEYS
+ if (k.mod.command) {
+ _scroll_lines_up();
+ break;
+ }
+#else
+ if (k.mod.command && k.mod.alt) {
+ _scroll_lines_up();
+ break;
+ }
+
if (k.mod.command)
cursor_set_line(0);
else
@@ -2084,7 +2094,17 @@ void TextEdit::_input_event(const InputEvent& p_input_event) {
scancode_handled=false;
break;
}
-#ifdef APPLE_STYLE_KEYS
+#ifndef APPLE_STYLE_KEYS
+ if (k.mod.command) {
+ _scroll_lines_down();
+ break;
+ }
+#else
+ if (k.mod.command && k.mod.alt) {
+ _scroll_lines_down();
+ break;
+ }
+
if (k.mod.command)
cursor_set_line(text.size()-1);
else
@@ -2498,6 +2518,36 @@ void TextEdit::_post_shift_selection() {
selection.selecting_text=true;
}
+void TextEdit::_scroll_lines_up() {
+ // adjust the vertical scroll
+ if (get_v_scroll() > 0) {
+ set_v_scroll(get_v_scroll() - 1);
+ }
+
+ // adjust the cursor
+ if (cursor_get_line() >= (get_visible_rows() + get_v_scroll()) && !selection.active) {
+ cursor_set_line((get_visible_rows() + get_v_scroll()) - 1, false);
+ }
+}
+
+void TextEdit::_scroll_lines_down() {
+ // calculate the maximum vertical scroll position
+ int max_v_scroll = get_line_count() - 1;
+ if (!scroll_past_end_of_file_enabled) {
+ max_v_scroll -= get_visible_rows() - 1;
+ }
+
+ // adjust the vertical scroll
+ if (get_v_scroll() < max_v_scroll) {
+ set_v_scroll(get_v_scroll() + 1);
+ }
+
+ // adjust the cursor
+ if ((cursor_get_line()) <= get_v_scroll() - 1 && !selection.active) {
+ cursor_set_line(get_v_scroll(), false);
+ }
+}
+
/**** TEXT EDIT CORE API ****/
void TextEdit::_base_insert_text(int p_line, int p_char,const String& p_text,int &r_end_line,int &r_end_column) {
diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h
index 09c2a4d729..193dd236d1 100644
--- a/scene/gui/text_edit.h
+++ b/scene/gui/text_edit.h
@@ -259,6 +259,9 @@ class TextEdit : public Control {
void _pre_shift_selection();
void _post_shift_selection();
+ void _scroll_lines_up();
+ void _scroll_lines_down();
+
// void mouse_motion(const Point& p_pos, const Point& p_rel, int p_button_mask);
Size2 get_minimum_size();