From 117925c92518f223ab99c897247ebabcd6f38a22 Mon Sep 17 00:00:00 2001 From: Mahdi Nazemi Date: Fri, 5 May 2023 15:26:39 -0700 Subject: [PATCH 1/5] Fix `zt` to consider context.vim's context height --- autoload/smooth_scroll.vim | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/autoload/smooth_scroll.vim b/autoload/smooth_scroll.vim index 17a6e8c..b9b7e94 100644 --- a/autoload/smooth_scroll.vim +++ b/autoload/smooth_scroll.vim @@ -56,7 +56,11 @@ function! smooth_scroll#top(visual) let cur_top = line('w0') + &scrolloff let target_top = line('.') - let num_down = l:target_top - l:cur_top + let context_height = -1 + if match(&runtimepath, 'context\.vim') != -1 + let [_, context_height] = context#context#get(context#line#get_base_line(line('.'))) + endif + let num_down = l:target_top - l:cur_top - (l:context_height + 1) if l:num_down > 0 call s:smooth_scroll('d', l:num_down, 0) endif From d6dd3c0e39f3333ea3acbf3c663a3530c1ae2bf2 Mon Sep 17 00:00:00 2001 From: Mahdi Nazemi Date: Fri, 5 May 2023 16:06:43 -0700 Subject: [PATCH 2/5] Move increment inside the conditional block --- autoload/smooth_scroll.vim | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/autoload/smooth_scroll.vim b/autoload/smooth_scroll.vim index b9b7e94..6e6d505 100644 --- a/autoload/smooth_scroll.vim +++ b/autoload/smooth_scroll.vim @@ -56,11 +56,12 @@ function! smooth_scroll#top(visual) let cur_top = line('w0') + &scrolloff let target_top = line('.') - let context_height = -1 + let context_height = 0 if match(&runtimepath, 'context\.vim') != -1 let [_, context_height] = context#context#get(context#line#get_base_line(line('.'))) + let context_height += 1 endif - let num_down = l:target_top - l:cur_top - (l:context_height + 1) + let num_down = l:target_top - l:cur_top - l:context_height if l:num_down > 0 call s:smooth_scroll('d', l:num_down, 0) endif From c7f3cf6ac150029c8e259afbd3618af70295ea43 Mon Sep 17 00:00:00 2001 From: Mahdi Nazemi Date: Fri, 5 May 2023 16:12:22 -0700 Subject: [PATCH 3/5] Make room for the context separator line --- autoload/smooth_scroll.vim | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/autoload/smooth_scroll.vim b/autoload/smooth_scroll.vim index 6e6d505..3342bdd 100644 --- a/autoload/smooth_scroll.vim +++ b/autoload/smooth_scroll.vim @@ -59,7 +59,10 @@ function! smooth_scroll#top(visual) let context_height = 0 if match(&runtimepath, 'context\.vim') != -1 let [_, context_height] = context#context#get(context#line#get_base_line(line('.'))) - let context_height += 1 + " Make room for the context separator line + if context_height > 0 + let context_height += 1 + endif endif let num_down = l:target_top - l:cur_top - l:context_height if l:num_down > 0 From a1c22313edfc1a63de8e9d064d3a282239b6f433 Mon Sep 17 00:00:00 2001 From: Mahdi Nazemi Date: Wed, 29 Apr 2026 19:51:10 -0700 Subject: [PATCH 4/5] fix: respect context height while scrolling --- autoload/smooth_scroll.vim | 40 ++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/autoload/smooth_scroll.vim b/autoload/smooth_scroll.vim index 3342bdd..85eca4c 100644 --- a/autoload/smooth_scroll.vim +++ b/autoload/smooth_scroll.vim @@ -15,13 +15,13 @@ set cpo&vim " Scroll the screen up function! smooth_scroll#up(dist) let move_only = max([0, &scrolloff - (line('w$') - line("."))]) - call s:smooth_scroll('u', a:dist - l:move_only, 1) + call s:smooth_scroll('u', max([0, a:dist - l:move_only]), 1) endfunction " Scroll the screen down function! smooth_scroll#down(dist) let move_only = max([0, &scrolloff - (line(".") - line('w0'))]) - call s:smooth_scroll('d', a:dist - l:move_only, 1) + call s:smooth_scroll('d', max([0, a:dist - l:move_only]), 1) endfunction " Scroll to the center @@ -56,14 +56,7 @@ function! smooth_scroll#top(visual) let cur_top = line('w0') + &scrolloff let target_top = line('.') - let context_height = 0 - if match(&runtimepath, 'context\.vim') != -1 - let [_, context_height] = context#context#get(context#line#get_base_line(line('.'))) - " Make room for the context separator line - if context_height > 0 - let context_height += 1 - endif - endif + let context_height = s:context_height() let num_down = l:target_top - l:cur_top - l:context_height if l:num_down > 0 call s:smooth_scroll('d', l:num_down, 0) @@ -99,11 +92,38 @@ endfunction " Functions " ============================================================================== +function! s:context_height() abort + if !exists('g:context') || type(g:context) != v:t_dict + return 0 + endif + if get(g:context, 'presenter', '') ==# 'preview' + return 0 + endif + if !exists('w:context') || type(w:context) != v:t_dict || get(w:context, 'enabled', get(g:context, 'enabled', 1)) == 0 + return 0 + endif + if get(g:context, 'enabled', 1) == 0 + return 0 + endif + if get(get(g:context, 'filetype_blacklist', {}), &filetype, 0) || get(get(g:context, 'buftype_blacklist', {}), &buftype, 0) + return 0 + endif + + let l:height = len(get(w:context, 'lines', [])) + + " Make room for context.vim's separator line when a context popup is visible. + return l:height > 0 ? l:height + get(g:context, 'show_border', 0) : 0 +endfunction + " Scroll the window smoothly " dir: Direction of the scroll. 'd' is downwards, 'u' is upwards " dist: Distance, or the total number of lines to scroll " move: when 1, move the cursor too function! s:smooth_scroll(dir, dist, move) + if a:dist <= 0 + return + endif + let move_cmd='' if a:move == 1 if a:dir ==# 'd' From 47c8083b38f470af652b98994fda528c8e1321d5 Mon Sep 17 00:00:00 2001 From: Mahdi Nazemi Date: Wed, 29 Apr 2026 20:20:54 -0700 Subject: [PATCH 5/5] fix: refresh context after top scroll --- autoload/smooth_scroll.vim | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/autoload/smooth_scroll.vim b/autoload/smooth_scroll.vim index 85eca4c..b17c90d 100644 --- a/autoload/smooth_scroll.vim +++ b/autoload/smooth_scroll.vim @@ -54,6 +54,7 @@ function! smooth_scroll#top(visual) endif let saved_mode=mode() + call s:prepare_context_top_scroll() let cur_top = line('w0') + &scrolloff let target_top = line('.') let context_height = s:context_height() @@ -61,6 +62,7 @@ function! smooth_scroll#top(visual) if l:num_down > 0 call s:smooth_scroll('d', l:num_down, 0) endif + call s:update_context_after_top_scroll() " Restore visual mode if l:saved_mode == "v" || l:saved_mode == "V" @@ -92,7 +94,7 @@ endfunction " Functions " ============================================================================== -function! s:context_height() abort +function! s:context_active() abort if !exists('g:context') || type(g:context) != v:t_dict return 0 endif @@ -109,12 +111,32 @@ function! s:context_height() abort return 0 endif + return 1 +endfunction + +function! s:context_height() abort + if !s:context_active() + return 0 + endif + let l:height = len(get(w:context, 'lines', [])) " Make room for context.vim's separator line when a context popup is visible. return l:height > 0 ? l:height + get(g:context, 'show_border', 0) : 0 endfunction +function! s:prepare_context_top_scroll() abort + if s:context_active() + let w:context.force_fix_strategy = 'scroll' + endif +endfunction + +function! s:update_context_after_top_scroll() abort + if exists('*context#update') && s:context_active() + silent! call context#update('smooth-scroll-zt') + endif +endfunction + " Scroll the window smoothly " dir: Direction of the scroll. 'd' is downwards, 'u' is upwards " dist: Distance, or the total number of lines to scroll