feat: enable/disable specific replacers

This commit is contained in:
2024-04-30 17:53:53 +03:00
committed by Chen Asraf
parent 5c0132fe95
commit fbb89b1b44
5 changed files with 56 additions and 2 deletions

View File

@@ -137,8 +137,7 @@ require("text-transform").setup({
debug = false,
-- Keymap configurations
keymap = {
-- Keymaps to open the telescope popup. Set to `false` or `nil` to disable keymapping for
-- the Telescope popup.
-- Keymap to open the telescope popup. Set to `false` or `nil` to disable keymapping
-- You can always customize your own keymapping manually.
telescope_popup = {
-- Opens the popup in normal mode
@@ -147,6 +146,20 @@ require("text-transform").setup({
["v"] = "<Leader>~",
},
},
---
--- Configurations for the text-transform replacers
--- Keys indicate the replacer name, and the value is a table with the following options:
---
--- - `enabled` (boolean): Enable or disable the replacer - disabled replacers do not show up in the popup.
replacers = {
camel_case = { enabled = true },
const_case = { enabled = true },
dot_case = { enabled = true },
kebab_case = { enabled = true },
pascal_case = { enabled = true },
snake_case = { enabled = true },
title_case = { enabled = true },
},
})
```

View File

@@ -28,6 +28,20 @@ Default values:
["v"] = "<Leader>~",
},
},
---
--- Configurations for the text-transform replacers
--- Keys indicate the replacer name, and the value is a table with the following options:
---
--- - `enabled` (boolean): Enable or disable the replacer - disabled replacers do not show up in the popup.
replacers = {
camel_case = { enabled = true },
const_case = { enabled = true },
dot_case = { enabled = true },
kebab_case = { enabled = true },
pascal_case = { enabled = true },
snake_case = { enabled = true },
title_case = { enabled = true },
},
}
local function init()

View File

@@ -22,6 +22,20 @@ TextTransform.options = {
["v"] = "<Leader>~",
},
},
---
--- Configurations for the text-transform replacers
--- Keys indicate the replacer name, and the value is a table with the following options:
---
--- - `enabled` (boolean): Enable or disable the replacer - disabled replacers do not show up in the popup.
replacers = {
camel_case = { enabled = true },
const_case = { enabled = true },
dot_case = { enabled = true },
kebab_case = { enabled = true },
pascal_case = { enabled = true },
snake_case = { enabled = true },
title_case = { enabled = true },
},
}
local function init()

View File

@@ -1,3 +1,4 @@
-- local config = require("text-transform.config")
local utils = require("text-transform.util")
local tt = require("text-transform.transformers")
local replacers = require("text-transform.replacers")
@@ -10,6 +11,7 @@ local function merge(table)
TextTransform = utils.merge(TextTransform, table)
end
-- merge(config)
merge(tt)
merge(replacers)
merge(state)

View File

@@ -57,6 +57,17 @@ local items = {
function TextTransform.popup()
state.save_positions()
local filtered = {}
local config = _G.TextTransform.options
for _, item in ipairs(items) do
if not config.replacers[item.value] or not config.replacers[item.value].enabled then
goto continue
end
table.insert(filtered, item)
::continue::
end
local picker = pickers.new(dropdown, {
prompt_title = "Change Case",
finder = finders.new_table({