summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGUI
diff options
context:
space:
mode:
authorthankyouverycool <66646555+thankyouverycool@users.noreply.github.com>2022-12-16 11:45:39 -0500
committerAndreas Kling <kling@serenityos.org>2022-12-20 10:22:27 +0100
commit4c81fbc8c42c7f1d7c7a9083d8d76f07102e5378 (patch)
tree9042ce2783f90d83347d3a6d4d6c4e78506fc312 /Userland/Libraries/LibGUI
parenta98d5c52f865b44ca15fbda0fbc356f90e44f21e (diff)
downloadserenity-4c81fbc8c42c7f1d7c7a9083d8d76f07102e5378.zip
LibGUI: Add Page{Up,Down} support for GlyphMapWidget
Diffstat (limited to 'Userland/Libraries/LibGUI')
-rw-r--r--Userland/Libraries/LibGUI/GlyphMapWidget.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGUI/GlyphMapWidget.cpp b/Userland/Libraries/LibGUI/GlyphMapWidget.cpp
index 15b7fbe77f..566ecbc8f6 100644
--- a/Userland/Libraries/LibGUI/GlyphMapWidget.cpp
+++ b/Userland/Libraries/LibGUI/GlyphMapWidget.cpp
@@ -367,6 +367,49 @@ void GlyphMapWidget::keydown_event(KeyEvent& event)
return;
}
+ {
+ auto first_visible_row = vertical_scrollbar().value() / vertical_scrollbar().step();
+ auto last_visible_row = first_visible_row + m_visible_rows;
+ auto current_row = (m_active_glyph - first_glyph) / columns();
+ auto page = m_active_glyph;
+
+ if (event.key() == KeyCode::Key_PageDown) {
+ auto current_page = m_active_glyph + m_columns * (last_visible_row - current_row);
+ auto next_page = m_active_glyph + m_columns * m_visible_rows;
+ auto remainder = m_active_glyph + m_columns * ((last_glyph - first_glyph) / columns() - current_row);
+ if (current_row < last_visible_row && current_page <= last_glyph)
+ page = current_page;
+ else if (next_page <= last_glyph)
+ page = next_page;
+ else if (remainder <= last_glyph)
+ page = remainder;
+ else
+ page = remainder - m_columns; // Bottom rows do not always extend across all columns
+ if (event.shift())
+ m_selection.extend_to(page);
+ set_active_glyph(page, event.shift() ? ShouldResetSelection::No : ShouldResetSelection::Yes);
+ scroll_to_glyph(m_active_glyph);
+ return;
+ }
+
+ if (event.key() == KeyCode::Key_PageUp) {
+ auto current_page = m_active_glyph - m_columns * (current_row - first_visible_row);
+ auto previous_page = m_active_glyph - m_columns * m_visible_rows;
+ auto remainder = m_active_glyph - m_columns * current_row;
+ if (current_row > first_visible_row && current_page >= first_glyph)
+ page = current_page;
+ else if (previous_page >= first_glyph)
+ page = previous_page;
+ else
+ page = remainder;
+ if (event.shift())
+ m_selection.extend_to(page);
+ set_active_glyph(page, event.shift() ? ShouldResetSelection::No : ShouldResetSelection::Yes);
+ scroll_to_glyph(m_active_glyph);
+ return;
+ }
+ }
+
event.ignore();
}