Skip to content

Commit a45548b

Browse files
committed
Add float version
1 parent 4dcee12 commit a45548b

3 files changed

Lines changed: 512 additions & 22 deletions

File tree

lua/spectre/init.lua

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ local config = require('spectre.config')
2424
local state = require('spectre.state')
2525
local state_utils = require('spectre.state_utils')
2626
local utils = require('spectre.utils')
27-
local ui = require('spectre.ui.buffer')
27+
local ui = nil
2828
local log = require('spectre._log')
2929
local async = require('plenary.async')
3030

@@ -38,6 +38,7 @@ M.setup = function(cfg)
3838
state.options[opt] = true
3939
end
4040
require('spectre.highlight').set_hl()
41+
4142
M.check_replace_cmd_bins()
4243
end
4344

@@ -119,6 +120,14 @@ M.open = function(opts)
119120
M.setup()
120121
end
121122

123+
if state.user_config.ui.default == 'buffer' then
124+
ui = require('spectre.ui.buffer')
125+
elseif state.user_config.ui.default == 'float' then
126+
ui = require('spectre.ui.float')
127+
else
128+
vim.notify('Invalid ui type: ' .. state.user_config.ui, vim.log.levels.ERROR)
129+
end
130+
122131
opts = vim.tbl_extend('force', {
123132
cwd = nil,
124133
is_insert_mode = state.user_config.is_insert_mode,
@@ -163,29 +172,9 @@ M.open = function(opts)
163172
end
164173
end
165174

166-
vim.wo.foldenable = false
167-
vim.bo.buftype = 'nofile'
168-
vim.bo.buflisted = false
169-
state.bufnr = api.nvim_get_current_buf()
170-
vim.cmd(string.format('file %s/spectre', state.bufnr))
171-
vim.bo.filetype = config.filetype
172-
api.nvim_buf_clear_namespace(state.bufnr, config.namespace_status, 0, -1)
173-
api.nvim_buf_clear_namespace(state.bufnr, config.namespace_result, 0, -1)
174-
api.nvim_buf_set_lines(state.bufnr, 0, -1, false, {})
175-
176-
vim.api.nvim_buf_attach(state.bufnr, false, {
177-
on_detach = M.stop,
178-
})
179-
ui.render_text_query(opts)
180-
181-
state.cwd = opts.cwd
182-
state.search_paths = opts.search_paths
183175
M.change_view('reset')
184-
ui.render_search_ui()
185176

186-
if opts.is_insert_mode == true then
187-
vim.api.nvim_feedkeys('A', 'n', true)
188-
end
177+
ui.open(opts)
189178

190179
M.mapping_buffer(state.bufnr)
191180

lua/spectre/ui/buffer.lua

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,32 @@ local api = vim.api
1212

1313
local M = {}
1414

15+
M.open = function(opts)
16+
vim.wo.foldenable = false
17+
vim.bo.buftype = 'nofile'
18+
vim.bo.buflisted = false
19+
state.bufnr = api.nvim_get_current_buf()
20+
vim.cmd(string.format('file %s/spectre', state.bufnr))
21+
vim.bo.filetype = config.filetype
22+
api.nvim_buf_clear_namespace(state.bufnr, config.namespace_status, 0, -1)
23+
api.nvim_buf_clear_namespace(state.bufnr, config.namespace_result, 0, -1)
24+
api.nvim_buf_set_lines(state.bufnr, 0, -1, false, {})
25+
26+
vim.api.nvim_buf_attach(state.bufnr, false, {
27+
on_detach = M.stop,
28+
})
29+
30+
M.render_text_query(opts)
31+
32+
state.cwd = opts.cwd
33+
state.search_paths = opts.search_paths
34+
M.render_search_ui()
35+
36+
if opts.is_insert_mode == true then
37+
vim.api.nvim_feedkeys('A', 'n', true)
38+
end
39+
end
40+
1541
---@param regex RegexEngine
1642
M.render_line = function(bufnr, namespace, text_opts, view_opts, regex)
1743
local cfg = state.user_config

0 commit comments

Comments
 (0)