@@ -107,12 +107,12 @@ void SurfaceListing::set_mode(RDRenderMode m) {
107107 this ->viewport ()->update ();
108108}
109109
110- void SurfaceListing::set_position (int row, int col) {
111- rd_surface_set_pos (m_surface, row, col);
110+ bool SurfaceListing::set_position (int row, int col) {
111+ return rd_surface_set_pos (m_surface, row, col);
112112}
113113
114- void SurfaceListing::select (int row, int col) {
115- rd_surface_select (m_surface, row, col);
114+ bool SurfaceListing::select (int row, int col) {
115+ return rd_surface_select (m_surface, row, col);
116116}
117117
118118bool SurfaceListing::go_back () {
@@ -239,10 +239,25 @@ void SurfaceListing::wheelEvent(QWheelEvent* e) {
239239
240240void SurfaceListing::keyPressEvent (QKeyEvent* e) {
241241 if (!utils::handle_key_press (this , e)) {
242- QScrollBar64* vscroll = this ->verticalScrollBar ();
243242 auto [row, col] = this ->get_position ();
244243
245- if (e->matches (QKeySequence::MoveToEndOfLine)) {
244+ if (e->matches (QKeySequence::MoveToNextLine)) {
245+ if (row + 1 < this ->visible_rows ()) {
246+ this ->set_position (row + 1 , col);
247+ }
248+ else {
249+ if (!rd_surface_scroll (m_surface, 1 )) return ;
250+ }
251+ }
252+ else if (e->matches (QKeySequence::MoveToPreviousLine)) {
253+ if (row - 1 >= 0 ) {
254+ this ->set_position (row - 1 , col);
255+ }
256+ else {
257+ if (!rd_surface_scroll (m_surface, -1 )) return ;
258+ }
259+ }
260+ else if (e->matches (QKeySequence::MoveToEndOfLine)) {
246261 rd_surface_set_pos (m_surface, row, this ->visible_columns ());
247262 }
248263 else if (e->matches (QKeySequence::MoveToNextPage)) {
@@ -252,12 +267,10 @@ void SurfaceListing::keyPressEvent(QKeyEvent* e) {
252267 if (!rd_surface_scroll (m_surface, -this ->visible_rows ())) return ;
253268 }
254269 else if (e->matches (QKeySequence::MoveToStartOfDocument)) {
255- vscroll->setValue (0 );
256- return ;
270+ rd_surface_set_pos (m_surface, 0 , col);
257271 }
258272 else if (e->matches (QKeySequence::MoveToEndOfDocument)) {
259- vscroll->setValue (vscroll->value () + this ->visible_rows () - 1 );
260- return ;
273+ rd_surface_set_pos (m_surface, this ->visible_rows (), col);
261274 }
262275 else if (e->matches (QKeySequence::SelectEndOfLine)) {
263276 rd_surface_select (m_surface, row, this ->visible_columns ());
@@ -340,7 +353,7 @@ int SurfaceListing::visible_columns() const {
340353}
341354
342355int SurfaceListing::visible_rows () const {
343- return qCeil (this ->viewport ()->height () / surface_renderer::cell_height ());
356+ return qFloor (this ->viewport ()->height () / surface_renderer::cell_height ());
344357}
345358
346359RDSurfacePos SurfaceListing::get_surface_coords (QPoint pt) const {
0 commit comments