@@ -7,8 +7,8 @@ local M = {}
7
7
-- window_get_visible_lines
8
8
-- { [1] = 28, [2] = 74 }
9
9
function M .window_get_visible_lines ()
10
- -- print('window_get_visible_lines()')
11
- return { vim .fn .line (" w0" ), vim .fn .line (" w$" ) }
10
+ -- print('window_get_visible_lines()')
11
+ return { vim .fn .line (" w0" ), vim .fn .line (" w$" ) }
12
12
end
13
13
14
14
-- Get the coordinates of the current selection
24
24
-- 1. run in command mode :vmap <c-a> <Cmd>:call CursorlessLoadExtension()<Cr>
25
25
-- 2. Select some text and hit ctrl+a
26
26
function M .buffer_get_selection ()
27
- local start_pos = vim .fn .getpos (" v" ) -- start of visual selection
28
- local start_line , start_col = start_pos [2 ], start_pos [3 ]
29
- local end_pos = vim .fn .getpos (" ." ) -- end of visual selection (cursor position)
30
- local end_line , end_col = end_pos [2 ], end_pos [3 ]
31
- local reverse = false
32
- local mode = vim .api .nvim_get_mode ().mode
27
+ local start_pos = vim .fn .getpos (" v" ) -- start of visual selection
28
+ local start_line , start_col = start_pos [2 ], start_pos [3 ]
29
+ local end_pos = vim .fn .getpos (" ." ) -- end of visual selection (cursor position)
30
+ local end_line , end_col = end_pos [2 ], end_pos [3 ]
31
+ local reverse = false
32
+ local mode = vim .api .nvim_get_mode ().mode
33
33
34
- -- Invert the values depending on if the cursor is before the start
35
- if end_line < start_line or end_col < start_col then
36
- start_line , start_col , end_line , end_col = end_line , end_col , start_line , start_col
37
- reverse = true
38
- end
34
+ -- Invert the values depending on if the cursor is before the start
35
+ if end_line < start_line or end_col < start_col then
36
+ start_line , start_col , end_line , end_col =
37
+ end_line , end_col , start_line , start_col
38
+ reverse = true
39
+ end
39
40
40
- -- See https://github.com/cursorless-dev/cursorless/issues/2537 if you want to add more modes
41
- if mode == " V" then
42
- -- Line and block-based visual modes are line-based, so we don't need to track the columns
43
- start_col = 1
44
- end_col = nil
45
- end
41
+ -- See https://github.com/cursorless-dev/cursorless/issues/2537 if you want to add more modes
42
+ if mode == " V" then
43
+ -- Line and block-based visual modes are line-based, so we don't need to track the columns
44
+ start_col = 1
45
+ end_col = nil
46
+ end
46
47
47
- return { start_line , start_col , end_line , end_col , reverse }
48
+ return { start_line , start_col , end_line , end_col , reverse }
48
49
end
49
50
50
51
-- https://github.com/nvim-treesitter/nvim-treesitter/blob/master/lua/nvim-treesitter/ts_utils.lua#L278
58
59
-- another example is :tmap <c-b> <Cmd>lua require("talon.cursorless").select_range(4, 0, 4, 38)<Cr>
59
60
-- NOTE: works for any mode (n,i,v,nt) except in t mode
60
61
function M .select_range (start_line , start_col , end_line , end_col )
61
- vim .cmd ([[ normal! :noh]] )
62
- vim .api .nvim_win_set_cursor (0 , { start_line , start_col })
63
- vim .cmd ([[ normal v]] )
64
- vim .api .nvim_win_set_cursor (0 , { end_line , end_col })
62
+ vim .cmd ([[ normal! :noh]] )
63
+ vim .api .nvim_win_set_cursor (0 , { start_line , start_col })
64
+ vim .cmd ([[ normal v]] )
65
+ vim .api .nvim_win_set_cursor (0 , { end_line , end_col })
65
66
end
66
67
67
68
return M
0 commit comments