Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lua/nvim-surround/buffer.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
local config = require("nvim-surround.config")

local M = {}

M.namespace = {
Expand Down Expand Up @@ -34,6 +32,7 @@ end
-- Move the cursor to a location in the buffer, depending on the `move_cursor` setting.
---@param pos { first_pos: position, sticky_pos: position, old_pos: position } Various positions in the buffer.
M.restore_curpos = function(pos)
local config = require("nvim-surround.config")
if config.get_opts().move_cursor == "begin" then
M.set_curpos(pos.first_pos)
elseif config.get_opts().move_cursor == "sticky" then
Expand Down
5 changes: 2 additions & 3 deletions lua/nvim-surround/motions.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
local buffer = require("nvim-surround.buffer")
local config = require("nvim-surround.config")

local M = {}

-- Determines whether the input character is a quote character.
Expand All @@ -16,6 +13,8 @@ end
---@return selection|nil @The selection that represents the text-object.
---@nodiscard
M.get_selection = function(motion)
local buffer = require("nvim-surround.buffer")
local config = require("nvim-surround.config")
local char = config.get_alias(motion:sub(2, 2))
local curpos = buffer.get_curpos()

Expand Down
5 changes: 3 additions & 2 deletions lua/nvim-surround/patterns.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
local buffer = require("nvim-surround.buffer")

local M = {}

-- Gets the EOL character for the current buffer, based on the file format.
Expand Down Expand Up @@ -45,6 +43,7 @@ end
---@return selection @The adjusted selection, handling multi-byte characters.
---@nodiscard
M.adjust_selection = function(selection)
local buffer = require("nvim-surround.buffer")
selection.first_pos = buffer.get_first_byte(selection.first_pos)
selection.last_pos = buffer.get_last_byte(selection.last_pos)
return selection
Expand All @@ -55,6 +54,7 @@ end
---@return selection|nil @The closest selection matching the pattern, if any.
---@nodiscard
M.get_selection = function(find)
local buffer = require("nvim-surround.buffer")
-- Get the current cursor position, buffer contents
local curpos = buffer.get_curpos()
local buffer_text = table.concat(buffer.get_lines(1, -1), end_of_line())
Expand Down Expand Up @@ -130,6 +130,7 @@ end
---@return selections|nil @The selections for the left and right delimiters.
---@nodiscard
M.get_selections = function(selection, pattern)
local buffer = require("nvim-surround.buffer")
local offset = M.pos_to_index(selection.first_pos)
local str = table.concat(buffer.get_text(selection), end_of_line())
-- Get the surrounding pair, and the start/end indices
Expand Down
8 changes: 4 additions & 4 deletions lua/nvim-surround/utils.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
local buffer = require("nvim-surround.buffer")
local config = require("nvim-surround.config")
local functional = require("nvim-surround.functional")

local M = {}

-- Do nothing.
Expand Down Expand Up @@ -42,12 +38,15 @@ end
---@return selections|nil @A table containing the start and end positions of the delimiters.
---@nodiscard
M.get_nearest_selections = function(char, action)
local config = require("nvim-surround.config")
local functional = require("nvim-surround.functional")
char = config.get_alias(char)
local chars = functional.to_list(config.get_opts().aliases[char] or char)
if not chars then
return nil
end

local buffer = require("nvim-surround.buffer")
local curpos = buffer.get_curpos()
local winview = vim.fn.winsaveview()
local selections_list = {}
Expand Down Expand Up @@ -79,6 +78,7 @@ end
---@return selections|nil @The best selections from the list.
---@nodiscard
M.filter_selections_list = function(selections_list)
local buffer = require("nvim-surround.buffer")
local curpos = buffer.get_curpos()
local best_selections
for _, cur_selections in ipairs(selections_list) do
Expand Down
Loading