File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- local config = require (" nvim-surround.config" )
2-
31local M = {}
42
53M .namespace = {
3432-- Move the cursor to a location in the buffer, depending on the `move_cursor` setting.
3533--- @param pos { first_pos : position , sticky_pos : position , old_pos : position } Various positions in the buffer.
3634M .restore_curpos = function (pos )
35+ local config = require (" nvim-surround.config" )
3736 if config .get_opts ().move_cursor == " begin" then
3837 M .set_curpos (pos .first_pos )
3938 elseif config .get_opts ().move_cursor == " sticky" then
Original file line number Diff line number Diff line change 1- local buffer = require (" nvim-surround.buffer" )
2- local config = require (" nvim-surround.config" )
3-
41local M = {}
52
63-- Determines whether the input character is a quote character.
1613--- @return selection | nil @The selection that represents the text-object.
1714--- @nodiscard
1815M .get_selection = function (motion )
16+ local buffer = require (" nvim-surround.buffer" )
17+ local config = require (" nvim-surround.config" )
1918 local char = config .get_alias (motion :sub (2 , 2 ))
2019 local curpos = buffer .get_curpos ()
2120
Original file line number Diff line number Diff line change 1- local buffer = require (" nvim-surround.buffer" )
2-
31local M = {}
42
53-- Gets the EOL character for the current buffer, based on the file format.
4543--- @return selection @The adjusted selection , handling multi-byte characters.
4644--- @nodiscard
4745M .adjust_selection = function (selection )
46+ local buffer = require (" nvim-surround.buffer" )
4847 selection .first_pos = buffer .get_first_byte (selection .first_pos )
4948 selection .last_pos = buffer .get_last_byte (selection .last_pos )
5049 return selection
5554--- @return selection | nil @The closest selection matching the pattern , if any.
5655--- @nodiscard
5756M .get_selection = function (find )
57+ local buffer = require (" nvim-surround.buffer" )
5858 -- Get the current cursor position, buffer contents
5959 local curpos = buffer .get_curpos ()
6060 local buffer_text = table.concat (buffer .get_lines (1 , - 1 ), end_of_line ())
130130--- @return selections | nil @The selections for the left and right delimiters.
131131--- @nodiscard
132132M .get_selections = function (selection , pattern )
133+ local buffer = require (" nvim-surround.buffer" )
133134 local offset = M .pos_to_index (selection .first_pos )
134135 local str = table.concat (buffer .get_text (selection ), end_of_line ())
135136 -- Get the surrounding pair, and the start/end indices
Original file line number Diff line number Diff line change 1- local buffer = require (" nvim-surround.buffer" )
2- local config = require (" nvim-surround.config" )
3- local functional = require (" nvim-surround.functional" )
4-
51local M = {}
62
73-- Do nothing.
4238--- @return selections | nil @A table containing the start and end positions of the delimiters.
4339--- @nodiscard
4440M .get_nearest_selections = function (char , action )
41+ local config = require (" nvim-surround.config" )
42+ local functional = require (" nvim-surround.functional" )
4543 char = config .get_alias (char )
4644 local chars = functional .to_list (config .get_opts ().aliases [char ] or char )
4745 if not chars then
4846 return nil
4947 end
5048
49+ local buffer = require (" nvim-surround.buffer" )
5150 local curpos = buffer .get_curpos ()
5251 local winview = vim .fn .winsaveview ()
5352 local selections_list = {}
7978--- @return selections | nil @The best selections from the list.
8079--- @nodiscard
8180M .filter_selections_list = function (selections_list )
81+ local buffer = require (" nvim-surround.buffer" )
8282 local curpos = buffer .get_curpos ()
8383 local best_selections
8484 for _ , cur_selections in ipairs (selections_list ) do
You can’t perform that action at this time.
0 commit comments