From fbb89b1b44dfb9b57cd241b7c574665cce7dab10 Mon Sep 17 00:00:00 2001 From: Chen Asraf Date: Tue, 30 Apr 2024 17:53:53 +0300 Subject: [PATCH] feat: enable/disable specific replacers --- README.md | 17 +++++++++++++++-- doc/text-transform.txt | 14 ++++++++++++++ lua/text-transform/config.lua | 14 ++++++++++++++ lua/text-transform/main.lua | 2 ++ lua/text-transform/telescope.lua | 11 +++++++++++ 5 files changed, 56 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 32ba6b8..18d1e9e 100644 --- a/README.md +++ b/README.md @@ -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"] = "~", }, }, + --- + --- 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 }, + }, }) ``` diff --git a/doc/text-transform.txt b/doc/text-transform.txt index 3af5c52..185a732 100644 --- a/doc/text-transform.txt +++ b/doc/text-transform.txt @@ -28,6 +28,20 @@ Default values: ["v"] = "~", }, }, + --- + --- 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() diff --git a/lua/text-transform/config.lua b/lua/text-transform/config.lua index b1bf497..65fdf32 100644 --- a/lua/text-transform/config.lua +++ b/lua/text-transform/config.lua @@ -22,6 +22,20 @@ TextTransform.options = { ["v"] = "~", }, }, + --- + --- 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() diff --git a/lua/text-transform/main.lua b/lua/text-transform/main.lua index 3efc1c2..0dd2a8e 100644 --- a/lua/text-transform/main.lua +++ b/lua/text-transform/main.lua @@ -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) diff --git a/lua/text-transform/telescope.lua b/lua/text-transform/telescope.lua index 3564b2e..49a2d9b 100644 --- a/lua/text-transform/telescope.lua +++ b/lua/text-transform/telescope.lua @@ -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({