mirror of
https://github.com/chenasraf/text-transform.nvim.git
synced 2026-05-17 17:48:04 +00:00
feat: allow sorter selection in config
This commit is contained in:
16
README.md
16
README.md
@@ -177,16 +177,16 @@ rest to use the defaults.
|
||||
|
||||
```lua
|
||||
require("text-transform").setup({
|
||||
-- Prints information about internals of the plugin. Very verbose, only useful for debugging.
|
||||
--- Prints information about internals of the plugin. Very verbose, only useful for debugging.
|
||||
debug = false,
|
||||
-- Keymap configurations
|
||||
--- Keymap configurations
|
||||
keymap = {
|
||||
-- Keymap to open the telescope popup. Set to `false` or `nil` to disable keymapping
|
||||
-- You can always customize your own keymapping manually.
|
||||
--- 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
|
||||
--- Opens the popup in normal mode
|
||||
["n"] = "<Leader>~",
|
||||
-- Opens the popup in visual/visual block modes
|
||||
--- Opens the popup in visual/visual block modes
|
||||
["v"] = "<Leader>~",
|
||||
},
|
||||
},
|
||||
@@ -204,6 +204,10 @@ require("text-transform").setup({
|
||||
snake_case = { enabled = true },
|
||||
title_case = { enabled = true },
|
||||
},
|
||||
|
||||
--- Sort the replacers in the popup.
|
||||
--- Possible values: 'frequency', 'name'
|
||||
sort_by = 'frequency',
|
||||
})
|
||||
```
|
||||
|
||||
|
||||
@@ -15,16 +15,16 @@ Your plugin configuration with its default values.
|
||||
Default values:
|
||||
>
|
||||
TextTransform.options = {
|
||||
-- Prints information about internals of the plugin. Very verbose, only useful for debugging.
|
||||
--- Prints information about internals of the plugin. Very verbose, only useful for debugging.
|
||||
debug = false,
|
||||
-- Keymap configurations
|
||||
--- Keymap configurations
|
||||
keymap = {
|
||||
-- Keymap to open the telescope popup. Set to `false` or `nil` to disable keymapping
|
||||
-- You can always customize your own keymapping manually.
|
||||
--- 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
|
||||
--- Opens the popup in normal mode
|
||||
["n"] = "<Leader>~",
|
||||
-- Opens the popup in visual/visual block modes
|
||||
--- Opens the popup in visual/visual block modes
|
||||
["v"] = "<Leader>~",
|
||||
},
|
||||
},
|
||||
@@ -42,6 +42,10 @@ Default values:
|
||||
snake_case = { enabled = true },
|
||||
title_case = { enabled = true },
|
||||
},
|
||||
|
||||
--- Sort the replacers in the popup.
|
||||
--- Possible values: 'frequency', 'name'
|
||||
sort_by = "frequency",
|
||||
}
|
||||
|
||||
local function init()
|
||||
|
||||
@@ -9,16 +9,16 @@ local TextTransform = {}
|
||||
--- Default values:
|
||||
---@eval return MiniDoc.afterlines_to_code(MiniDoc.current.eval_section)
|
||||
TextTransform.options = {
|
||||
-- Prints information about internals of the plugin. Very verbose, only useful for debugging.
|
||||
--- Prints information about internals of the plugin. Very verbose, only useful for debugging.
|
||||
debug = false,
|
||||
-- Keymap configurations
|
||||
--- Keymap configurations
|
||||
keymap = {
|
||||
-- Keymap to open the telescope popup. Set to `false` or `nil` to disable keymapping
|
||||
-- You can always customize your own keymapping manually.
|
||||
--- 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
|
||||
--- Opens the popup in normal mode
|
||||
["n"] = "<Leader>~",
|
||||
-- Opens the popup in visual/visual block modes
|
||||
--- Opens the popup in visual/visual block modes
|
||||
["v"] = "<Leader>~",
|
||||
},
|
||||
},
|
||||
@@ -36,6 +36,10 @@ TextTransform.options = {
|
||||
snake_case = { enabled = true },
|
||||
title_case = { enabled = true },
|
||||
},
|
||||
|
||||
--- Sort the replacers in the popup.
|
||||
--- Possible values: 'frequency', 'name'
|
||||
sort_by = "frequency",
|
||||
}
|
||||
|
||||
local function init()
|
||||
|
||||
@@ -138,10 +138,14 @@ end
|
||||
--- This allows to treat all ranges equally and allows to work on each selection without knowing
|
||||
--- the full information around the selection logic.
|
||||
function TextTransform.get_visual_selection_details()
|
||||
if not state.positions then
|
||||
D.log("replacers", "No positions saved")
|
||||
return {}
|
||||
end
|
||||
D.log(
|
||||
"replacers",
|
||||
"Getting visual selection details - mode: %s, is_visual: %s, is_block: %s",
|
||||
vim.inspect(state.positions),
|
||||
state.positions.mode,
|
||||
utils.is_visual_mode(),
|
||||
utils.is_block_visual_mode()
|
||||
)
|
||||
|
||||
@@ -97,6 +97,12 @@ local frequency_sorter = Sorter:new({
|
||||
return final_score
|
||||
end,
|
||||
})
|
||||
|
||||
local sorter_map = {
|
||||
frequency = frequency_sorter,
|
||||
name = generic_sorter,
|
||||
}
|
||||
|
||||
---@diagnostic disable-next-line: unused-local
|
||||
-- for _i, k in pairs(default_ordered_keys) do
|
||||
-- local v = map[k]
|
||||
@@ -114,11 +120,14 @@ local frequency_sorter = Sorter:new({
|
||||
--- made.
|
||||
function TextTransform.popup()
|
||||
state.save_positions()
|
||||
load_frequency()
|
||||
|
||||
local filtered = {}
|
||||
print(vim.inspect(_G.TextTransform.config))
|
||||
local config = _G.TextTransform.config
|
||||
local sorter = sorter_map[config.sort_by] or generic_sorter
|
||||
|
||||
if config.sort_by == "frequency" then
|
||||
load_frequency()
|
||||
end
|
||||
|
||||
for _, item in ipairs(items) do
|
||||
if not config.replacers[item.value] or not config.replacers[item.value].enabled then
|
||||
@@ -134,7 +143,7 @@ function TextTransform.popup()
|
||||
results = items,
|
||||
entry_maker = entry_maker,
|
||||
}),
|
||||
sorter = frequency_sorter,
|
||||
sorter = sorter,
|
||||
attach_mappings = function(prompt_bufnr)
|
||||
actions.select_default:replace(function()
|
||||
local selection = action_state.get_selected_entry()
|
||||
|
||||
Reference in New Issue
Block a user