Skip to content

Commit

Permalink
feat: <C-c> to toggle case sensitivity (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ajaymamtora authored Aug 24, 2024
1 parent 5d6f15e commit 62ab38d
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ require("rip-substitute").setup {
prevSubst = "<Up>",
nextSubst = "<Down>",
toggleFixedStrings = "<C-f>",
toggleCaseSensitive = "<C-c>",
openAtRegex101 = "R",
},
incrementalPreview = {
Expand Down
1 change: 1 addition & 0 deletions lua/rip-substitute/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ local defaultConfig = {
prevSubst = "<Up>",
nextSubst = "<Down>",
toggleFixedStrings = "<C-f>",
toggleCaseSensitive = "<C-c>",
openAtRegex101 = "R",
},
incrementalPreview = {
Expand Down
16 changes: 12 additions & 4 deletions lua/rip-substitute/popup-win.lua
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,11 @@ local function setPopupTitle()
if state.range then
title = "Range: " .. state.range.start
if state.range.start ~= state.range.end_ then title = title .. "" .. state.range.end_ end
if state.useFixedStrings then title = title .. " [Fixed Strings]" end
elseif state.useFixedStrings then
title = "[Fixed Strings]"
end

title = state.useFixedStrings and title .. " -F" or title
title = state.useCaseSensitive and title .. " -s" or title .. " -i"

vim.api.nvim_win_set_config(state.popupWinNr, { title = " " .. title .. " " })
end

Expand Down Expand Up @@ -276,6 +276,14 @@ local function createKeymaps()
updateMatchCount()
setPopupTitle()
end, opts)

-- toggle case sensitive
vim.keymap.set({ "n", "x" }, keymaps.toggleCaseSensitive, function()
state.useCaseSensitive = not state.useCaseSensitive
require("rip-substitute.rg-operations").incrementalPreviewAndMatchCount()
updateMatchCount()
setPopupTitle()
end, opts)
end

--------------------------------------------------------------------------------
Expand All @@ -297,7 +305,7 @@ function M.openSubstitutionPopup()
local m = config.keymaps
local keymapHint = #state.popupHistory == 0
and ("%s confirm %s abort"):format(m.confirm, m.abort)
or ("%s/%s history %s literal"):format(m.prevSubst, m.nextSubst, m.toggleFixedStrings)
or ("%s/%s history %s literal"):format(m.prevSubst, m.nextSubst, m.toggleFixedStrings)
keymapHint = keymapHint -- using only utf symbols, so they work w/o nerd fonts
:gsub("<[Cc][Rr]>", "")
:gsub("<[dD]own>", "")
Expand Down
1 change: 1 addition & 0 deletions lua/rip-substitute/rg-operations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ local function runRipgrep(rgArgs)
config.regexOptions.pcre2 and "--pcre2" or "--no-pcre2",
"--" .. config.regexOptions.casing,
state.useFixedStrings and "--fixed-strings" or "--no-fixed-strings",
state.useCaseSensitive and "--case-sensitive" or "--ignore-case",
windowsEol and "--crlf" or "--no-crlf", -- see #17
}
vim.list_extend(args, rgArgs)
Expand Down
2 changes: 2 additions & 0 deletions lua/rip-substitute/state.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ local M = {}
---@field searchPrefill? string
---@field rememberedPrefill? string
---@field useFixedStrings? boolean
---@field useCaseSensitive? boolean
M.state = {
popupHistory = {},
matchCount = 0,
useFixedStrings = false,
useCaseSensitive = false,
}

---@type string
Expand Down

0 comments on commit 62ab38d

Please sign in to comment.