|
19 | 19 | local M = {} |
20 | 20 |
|
21 | 21 | local core = require('search-replace.core') |
22 | | - |
23 | | ----@class SearchReplaceKeymapConfig |
24 | | ----@field enable boolean Whether to enable keymaps |
25 | | ----@field populate? string Normal/Visual mode keymap to populate search line |
26 | | ----@field toggle_g? string Keymap to toggle global flag |
27 | | ----@field toggle_c? string Keymap to toggle confirm flag |
28 | | ----@field toggle_i? string Keymap to toggle case-insensitive flag |
29 | | ----@field toggle_replace? string Keymap to toggle replace term |
30 | | ----@field toggle_range? string Keymap to cycle range |
31 | | ----@field toggle_separator? string Keymap to cycle separator |
32 | | ----@field toggle_magic? string Keymap to cycle magic mode |
33 | | ----@field toggle_dashboard? string Keymap to toggle dashboard |
34 | | - |
35 | | ----@class SearchReplaceDashboardSymbols |
36 | | ----@field active string Symbol for active flag indicator |
37 | | ----@field inactive string Symbol for inactive flag indicator |
38 | | - |
39 | | ----@class SearchReplaceDashboardHighlights |
40 | | ----@field title string Highlight group for title |
41 | | ----@field key string Highlight group for key |
42 | | ----@field arrow string Highlight group for arrow |
43 | | ----@field active_desc string Highlight group for active description |
44 | | ----@field inactive_desc string Highlight group for inactive description |
45 | | ----@field active_indicator string Highlight group for active indicator |
46 | | ----@field inactive_indicator string Highlight group for inactive indicator |
47 | | ----@field status_label string Highlight group for status label |
48 | | ----@field status_value string Highlight group for status value |
49 | | - |
50 | | ----@class SearchReplaceDashboardConfig |
51 | | ----@field enable boolean Whether to enable the dashboard |
52 | | ----@field symbols SearchReplaceDashboardSymbols Visual symbols configuration |
53 | | ----@field highlights SearchReplaceDashboardHighlights Highlight groups configuration |
54 | | - |
55 | | ----@class SearchReplaceConfig |
56 | | ----@field keymaps SearchReplaceKeymapConfig Keymaps configuration |
57 | | ----@field dashboard SearchReplaceDashboardConfig Dashboard configuration |
58 | | ----@field separators string[] Available separator characters |
59 | | ----@field magic_modes string[] Available magic modes |
60 | | ----@field flags string[] Available flags |
61 | | ----@field default_range string Default range for substitute command |
62 | | ----@field default_flags string Default flags for substitute command |
63 | | ----@field default_magic string Default magic mode |
64 | | - |
65 | | ----@type SearchReplaceConfig |
66 | | -local default_config = { |
67 | | - -- Keymaps configuration |
68 | | - keymaps = { |
69 | | - enable = true, |
70 | | - populate = '<leader>r', -- Normal/Visual mode |
71 | | - toggle_g = '<M-g>', -- Toggle global flag |
72 | | - toggle_c = '<M-c>', -- Toggle confirm flag |
73 | | - toggle_i = '<M-i>', -- Toggle case-insensitive |
74 | | - toggle_replace = '<M-d>', -- Toggle replace term |
75 | | - toggle_range = '<M-5>', -- Cycle range |
76 | | - toggle_separator = '<M-/>', -- Cycle separator |
77 | | - toggle_magic = '<M-m>', -- Cycle magic mode |
78 | | - toggle_dashboard = '<M-h>', -- Toggle dashboard |
79 | | - }, |
80 | | - -- Dashboard configuration |
81 | | - dashboard = { |
82 | | - enable = true, |
83 | | - symbols = { |
84 | | - active = '*', |
85 | | - inactive = 'o', |
86 | | - }, |
87 | | - highlights = { |
88 | | - title = 'Title', |
89 | | - key = 'Special', |
90 | | - arrow = 'Comment', |
91 | | - active_desc = 'String', |
92 | | - inactive_desc = 'Comment', |
93 | | - active_indicator = 'DiagnosticOk', |
94 | | - inactive_indicator = 'Comment', |
95 | | - status_label = 'Comment', |
96 | | - status_value = 'Constant', |
97 | | - }, |
98 | | - }, |
99 | | - -- Core configuration |
100 | | - separators = { '/', '?', '#', ':', '@' }, |
101 | | - magic_modes = { '\\v', '\\m', '\\M', '\\V', '' }, |
102 | | - flags = { 'g', 'c', 'i' }, |
103 | | - default_range = '.,$s', |
104 | | - default_flags = 'gc', |
105 | | - default_magic = '\\V', |
106 | | -} |
107 | | - |
108 | | ----@type SearchReplaceConfig |
109 | | -local config = vim.deepcopy(default_config) |
| 22 | +local config_module = require('search-replace.config') |
110 | 23 |
|
111 | 24 | ---Setup keymaps for search-replace functionality |
112 | 25 | ---@param keymap_config SearchReplaceKeymapConfig |
|
193 | 106 | --- Setup the plugin with user configuration |
194 | 107 | ---@param opts? table User configuration options |
195 | 108 | function M.setup(opts) |
196 | | - opts = opts or {} |
197 | | - |
198 | | - -- Merge configuration |
199 | | - config = vim.tbl_deep_extend('force', default_config, opts) |
| 109 | + -- Merge user options with defaults in centralized config |
| 110 | + config_module.setup(opts) |
| 111 | + local config = config_module.get() |
200 | 112 |
|
201 | 113 | -- Setup core module |
202 | 114 | core.setup({ |
@@ -251,7 +163,7 @@ M.is_active = core.is_active |
251 | 163 | ---Get the current configuration |
252 | 164 | ---@return SearchReplaceConfig config The current configuration |
253 | 165 | function M.get_config() |
254 | | - return config |
| 166 | + return config_module.get() |
255 | 167 | end |
256 | 168 |
|
257 | 169 | return M |
0 commit comments