@@ -3,35 +3,37 @@ local hint = require'hop.hint'
3
3
local M = {}
4
4
5
5
local function window_context (win_handle , cursor_pos )
6
- -- get a bunch of information about the window and the cursor
7
- vim .api .nvim_set_current_win (win_handle )
8
- local win_info = vim .fn .getwininfo (win_handle )[1 ]
9
- local win_view = vim .fn .winsaveview ()
10
- local top_line = win_info .topline - 1
11
- local bot_line = win_info .botline
12
-
13
- -- NOTE: due to an (unknown yet) bug in neovim, the sign_width is not correctly reported when shifting the window
14
- -- view inside a non-wrap window, so we can’t rely on this; for this reason, we have to implement a weird hack that
15
- -- is going to disable the signs while hop is running (I’m sorry); the state is restored after jump
16
- -- local left_col_offset = win_info.variables.context.number_width + win_info.variables.context.sign_width
17
- local win_width = nil
18
-
19
- -- hack to get the left column offset in nowrap
20
- if not vim .wo .wrap then
21
- vim .api .nvim_win_set_cursor (win_handle , { cursor_pos [1 ], 0 })
22
- local left_col_offset = vim .fn .wincol () - 1
23
- vim .fn .winrestview (win_view )
24
- win_width = win_info .width - left_col_offset
25
- end
6
+ -- get window context without changing current window
7
+ return vim .api .nvim_win_call (win_handle , function ()
8
+ -- get a bunch of information about the window and the cursor
9
+ local win_info = vim .fn .getwininfo (win_handle )[1 ]
10
+ local win_view = vim .fn .winsaveview ()
11
+ local top_line = win_info .topline - 1
12
+ local bot_line = win_info .botline
13
+
14
+ -- NOTE: due to an (unknown yet) bug in neovim, the sign_width is not correctly reported when shifting the window
15
+ -- view inside a non-wrap window, so we can’t rely on this; for this reason, we have to implement a weird hack that
16
+ -- is going to disable the signs while hop is running (I’m sorry); the state is restored after jump
17
+ -- local left_col_offset = win_info.variables.context.number_width + win_info.variables.context.sign_width
18
+ local win_width = nil
19
+
20
+ -- hack to get the left column offset in nowrap
21
+ if not vim .wo .wrap then
22
+ vim .api .nvim_win_set_cursor (win_handle , { cursor_pos [1 ], 0 })
23
+ local left_col_offset = vim .fn .wincol () - 1
24
+ vim .fn .winrestview (win_view )
25
+ win_width = win_info .width - left_col_offset
26
+ end
26
27
27
- return {
28
- hwin = win_handle ,
29
- cursor_pos = cursor_pos ,
30
- top_line = top_line ,
31
- bot_line = bot_line ,
32
- win_width = win_width ,
33
- col_offset = win_view .leftcol
34
- }
28
+ return {
29
+ hwin = win_handle ,
30
+ cursor_pos = cursor_pos ,
31
+ top_line = top_line ,
32
+ bot_line = bot_line ,
33
+ win_width = win_width ,
34
+ col_offset = win_view .leftcol
35
+ }
36
+ end )
35
37
end
36
38
37
39
-- Collect all multi-windows's context:
0 commit comments