diff options
| author | Paulb23 | 2016-04-27 18:32:14 +0100 |
|---|---|---|
| committer | Rémi Verschelde | 2016-04-29 07:42:08 +0200 |
| commit | 517518ae9a2e8c7aa891cbd101dbee95750eac27 (patch) | |
| tree | 0ffec2fba6651a1460f636c0801276b175be8b07 /scene/gui/text_edit.cpp | |
| parent | 084ce221d73b0b7666080a9357f3a993e6c4700c (diff) | |
| download | godot-517518ae9a2e8c7aa891cbd101dbee95750eac27.tar.gz godot-517518ae9a2e8c7aa891cbd101dbee95750eac27.tar.zst godot-517518ae9a2e8c7aa891cbd101dbee95750eac27.zip | |
Added scroll lines, issue 4243
(cherry picked from commit 54244e0e1d37c03d86b1628df062b23c09a79c43)
Diffstat (limited to 'scene/gui/text_edit.cpp')
| -rw-r--r-- | scene/gui/text_edit.cpp | 54 |
1 files changed, 52 insertions, 2 deletions
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index bc2f9c0a4..08077f858 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -2021,7 +2021,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 @@ -2048,7 +2058,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 @@ -2462,6 +2482,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) { |
