From 38d4a75180d99618cfe3a254355e69fc5bb479de Mon Sep 17 00:00:00 2001 From: JustTaken Date: Sat, 20 Jul 2024 23:11:43 -0400 Subject: [PATCH 1/3] Take in account scrolloff when moving viewport `vt` and `vb` respect custom scroll offset --- src/normal.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/normal.cc b/src/normal.cc index af4d5fb18..d88e26a42 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -383,6 +383,9 @@ void view_commands(Context& context, NormalParams params) const BufferCoord cursor = context.selections().main().cursor(); Window& window = context.window(); + const DisplayCoord max_offset{(window.dimensions().line - 1)/2, (window.dimensions().column - 1)/2}; + const DisplayCoord scrolloff = + std::min(context.options()["scrolloff"].get(), max_offset); switch (*cp) { case 'v': @@ -394,10 +397,10 @@ void view_commands(Context& context, NormalParams params) context.buffer()[cursor.line].column_count_to(cursor.column)); break; case 't': - window.display_line_at(cursor.line, 0); + window.display_line_at(cursor.line, scrolloff.line); break; case 'b': - window.display_line_at(cursor.line, window.dimensions().line-1); + window.display_line_at(cursor.line, window.dimensions().line-1-scrolloff.line); break; case '<': window.display_column_at(context.buffer()[cursor.line].column_count_to(cursor.column), 0); From cbe2997bb579efa95601944ce262297cac85860a Mon Sep 17 00:00:00 2001 From: JustTaken Date: Sat, 20 Jul 2024 23:42:36 -0400 Subject: [PATCH 2/3] JustTaken Copyright Waiver I dedicate any and all copyright interest in this software to the public domain. I make this dedication for the benefit of the public at large and to the detriment of my heirs and successors. I intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law. From ab7bfec047c67c9d4f64cc0ef50dd9065e5f3362 Mon Sep 17 00:00:00 2001 From: JustTaken Date: Mon, 22 Jul 2024 16:20:42 -0400 Subject: [PATCH 3/3] Fix logic to get minimun custom offset Now the scrolloff can be specified in the configuration file and if either one of the column or line offset given is too large to fit in the buffer, half of the window dimension is taken in it's place. `v<` and `v>` account custom scroll offset as well. --- src/normal.cc | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/normal.cc b/src/normal.cc index d88e26a42..e00d09765 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -383,9 +383,10 @@ void view_commands(Context& context, NormalParams params) const BufferCoord cursor = context.selections().main().cursor(); Window& window = context.window(); - const DisplayCoord max_offset{(window.dimensions().line - 1)/2, (window.dimensions().column - 1)/2}; - const DisplayCoord scrolloff = - std::min(context.options()["scrolloff"].get(), max_offset); + + const DisplayCoord scrolloff = context.options()["scrolloff"].get(); + const LineCount line_offset{std::min((window.dimensions().line - 1) / 2, scrolloff.line)}; + const ColumnCount column_offset{std::min((window.dimensions().column - 1) / 2, scrolloff.column)}; switch (*cp) { case 'v': @@ -397,17 +398,18 @@ void view_commands(Context& context, NormalParams params) context.buffer()[cursor.line].column_count_to(cursor.column)); break; case 't': - window.display_line_at(cursor.line, scrolloff.line); + window.display_line_at(cursor.line, line_offset); break; case 'b': - window.display_line_at(cursor.line, window.dimensions().line-1-scrolloff.line); + window.display_line_at(cursor.line, window.dimensions().line-1-line_offset); break; case '<': - window.display_column_at(context.buffer()[cursor.line].column_count_to(cursor.column), 0); + window.display_column_at(context.buffer()[cursor.line].column_count_to(cursor.column), + column_offset); break; case '>': window.display_column_at(context.buffer()[cursor.line].column_count_to(cursor.column), - window.dimensions().column-1); + window.dimensions().column-1-column_offset); break; case 'h': window.scroll(-std::max(1, count));