Skip to content

Commit

Permalink
refactor: keymap configs
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisgrieser committed Dec 24, 2024
1 parent 14467ef commit 37babba
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ require("rip-substitute").setup {
abort = "q",
confirm = "<CR>",
insertModeConfirm = "<C-CR>",
prevSubst = "<Up>",
nextSubst = "<Down>",
prevSubstitutionInHistory = "<Up>",
nextSubstitutionInHistory = "<Down>",
toggleFixedStrings = "<C-f>", -- ripgrep's `--fixed-strings`
toggleIgnoreCase = "<C-c>", -- ripgrep's `--ignore-case`
openAtRegex101 = "R",
Expand Down
12 changes: 9 additions & 3 deletions lua/rip-substitute/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ local defaultConfig = {
abort = "q",
confirm = "<CR>",
insertModeConfirm = "<C-CR>",
prevSubst = "<Up>",
nextSubst = "<Down>",
prevSubstitutionInHistory = "<Up>",
nextSubstitutionInHistory = "<Down>",
toggleFixedStrings = "<C-f>", -- ripgrep's `--fixed-strings`
toggleIgnoreCase = "<C-c>", -- ripgrep's `--ignore-case`
openAtRegex101 = "R",
Expand Down Expand Up @@ -72,12 +72,18 @@ function M.setup(userConfig)
require("rip-substitute.state").state.useIgnoreCase = true
end

-- DEPRECATION
-- DEPRECATION (2024-11-20)
if M.config.notificationOnSuccess then ---@diagnostic disable-line: undefined-field
local msg =
"`notificationOnSuccess` has been deprecated. Use `notification.onSuccess` instead."
notify(msg, "warn")
end
-- DEPRECATION (2024-11-20)
if M.config.keymaps.prevSubst or M.config.keymaps.nextSubst then ---@diagnostic disable-line: undefined-field
local msg = "`keymaps.prevSubst` and `keymaps.prevSubst` have been deprecated. "
.. "Use `keymaps.prevSubstitutionInHistory` and `keymaps.nextSubstitutionInHistory` instead."
notify(msg, "warn")
end

-- VALIDATE `rg` installations not built with `pcre2`, see #3
if M.config.regexOptions.pcre2 then
Expand Down
8 changes: 4 additions & 4 deletions lua/rip-substitute/popup-win.lua
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ local function createKeymaps()

-- history keymaps
state.historyPosition = #state.popupHistory + 1
keymap("n", maps.prevSubst, function()
keymap("n", maps.prevSubstitutionInHistory, function()
if state.historyPosition < 2 then return end
if state.historyPosition == #state.popupHistory + 1 then
state.popupPresentContent = vim.api.nvim_buf_get_lines(state.popupBufNr, 0, -1, true)
Expand All @@ -262,7 +262,7 @@ local function createKeymaps()
local content = state.popupHistory[state.historyPosition]
vim.api.nvim_buf_set_lines(state.popupBufNr, 0, -1, false, content)
end)
keymap("n", maps.nextSubst, function()
keymap("n", maps.nextSubstitutionInHistory, function()
if state.historyPosition == #state.popupHistory + 1 then return end -- already at present
state.historyPosition = state.historyPosition + 1
local content = state.historyPosition == #state.popupHistory + 1 and state.popupPresentContent
Expand Down Expand Up @@ -290,8 +290,8 @@ local function createKeymaps()
("- [%s] abort"):format(maps.abort),
("- [%s] confirm"):format(maps.confirm),
("- [%s] confirm (insert mode)"):format(maps.insertModeConfirm),
("- [%s] next in history"):format(maps.nextSubst),
("- [%s] previous in history"):format(maps.prevSubst),
("- [%s] previous in history"):format(maps.prevSubstitutionInHistory),
("- [%s] next in history"):format(maps.nextSubstitutionInHistory),
("- [%s] toggle `--fixed-strings`"):format(maps.toggleFixedStrings),
("- [%s] toggle `--ignore-case`"):format(maps.toggleIgnoreCase),
("- [%s] open at regex101"):format(maps.openAtRegex101),
Expand Down

0 comments on commit 37babba

Please sign in to comment.