From 2069bc5b27871ad3ac3a7dc03313a49e9cceb0ca Mon Sep 17 00:00:00 2001 From: Liu-Cheng Xu Date: Fri, 27 Sep 2024 10:41:46 +0800 Subject: [PATCH] Fix open action regression for filer provider (#1093) * Fix open action regression for filer provider Close #1092 * Friendly message for igrep --- autoload/clap/selection.vim | 6 ++++++ autoload/clap/util.vim | 6 ++++++ crates/maple_core/src/stdio_server/input.rs | 9 +++++++++ .../src/stdio_server/provider/impls/filer.rs | 11 +++++++++++ .../src/stdio_server/provider/impls/igrep.rs | 5 +++++ 5 files changed, 37 insertions(+) diff --git a/autoload/clap/selection.vim b/autoload/clap/selection.vim index a690b228e..7d595afec 100644 --- a/autoload/clap/selection.vim +++ b/autoload/clap/selection.vim @@ -77,6 +77,12 @@ endfunction " Apply the open action specified by `g:clap_open_action` given the (selected) lines. function! clap#selection#try_open(action) abort + " ctrl-t/ctrl-x/ctrl-v are handled on the Rust side for filer. + if g:clap.provider.id ==# 'filer' + call clap#client#notify_provider(a:action) + return + endif + if !has_key(g:clap_open_action, a:action) \ || g:clap.display.get_lines() == [g:clap_no_matches_msg] return diff --git a/autoload/clap/util.vim b/autoload/clap/util.vim index 1189021d4..eb67f5229 100644 --- a/autoload/clap/util.vim +++ b/autoload/clap/util.vim @@ -175,5 +175,11 @@ function! clap#util#reload_current_file() abort noautocmd call setpos('.', save_cursor) endfunction +function! clap#util#sink_open(cmd, file) abort + call g:clap.start.goto_win() + execute a:cmd a:file + call clap#_exit_provider() +endfunction + let &cpoptions = s:save_cpo unlet s:save_cpo diff --git a/crates/maple_core/src/stdio_server/input.rs b/crates/maple_core/src/stdio_server/input.rs index 2e92724f8..571be4686 100644 --- a/crates/maple_core/src/stdio_server/input.rs +++ b/crates/maple_core/src/stdio_server/input.rs @@ -84,6 +84,12 @@ pub enum KeyEventType { CtrlN, // CtrlP, + // + CtrlT, + // + CtrlX, + // + CtrlV, } pub type ActionEvent = (PluginId, PluginAction); @@ -139,6 +145,9 @@ impl Event { "tab" => Ok(Self::Key((Tab, notification.params))), "ctrl-n" => Ok(Self::Key((CtrlN, notification.params))), "ctrl-p" => Ok(Self::Key((CtrlP, notification.params))), + "ctrl-t" => Ok(Self::Key((CtrlT, notification.params))), + "ctrl-x" => Ok(Self::Key((CtrlX, notification.params))), + "ctrl-v" => Ok(Self::Key((CtrlV, notification.params))), "shift-up" => Ok(Self::Key((ShiftUp, notification.params))), "shift-down" => Ok(Self::Key((ShiftDown, notification.params))), "backspace" => Ok(Self::Key((Backspace, notification.params))), diff --git a/crates/maple_core/src/stdio_server/provider/impls/filer.rs b/crates/maple_core/src/stdio_server/provider/impls/filer.rs index 4cf668fdd..17c48147b 100644 --- a/crates/maple_core/src/stdio_server/provider/impls/filer.rs +++ b/crates/maple_core/src/stdio_server/provider/impls/filer.rs @@ -348,6 +348,14 @@ impl FilerProvider { Ok(()) } + + async fn sink_open(&self, open_cmd: &str, ctx: &Context) -> Result<()> { + let curline = self.current_line(ctx).await?; + let target_dir = self.current_dir.join(curline); + ctx.vim + .exec("clap#util#sink_open", (open_cmd, target_dir))?; + Ok(()) + } } #[async_trait::async_trait] @@ -424,6 +432,9 @@ impl ClapProvider for FilerProvider { KeyEventType::ShiftDown => ctx.scroll_preview(Direction::Down).await, KeyEventType::CtrlN => ctx.next_input().await, KeyEventType::CtrlP => ctx.prev_input().await, + KeyEventType::CtrlT => self.sink_open("tab split", ctx).await, + KeyEventType::CtrlX => self.sink_open("split", ctx).await, + KeyEventType::CtrlV => self.sink_open("vsplit", ctx).await, } } } diff --git a/crates/maple_core/src/stdio_server/provider/impls/igrep.rs b/crates/maple_core/src/stdio_server/provider/impls/igrep.rs index a613a9ed3..4d7cd507b 100644 --- a/crates/maple_core/src/stdio_server/provider/impls/igrep.rs +++ b/crates/maple_core/src/stdio_server/provider/impls/igrep.rs @@ -481,6 +481,11 @@ impl ClapProvider for IgrepProvider { KeyEventType::Tab => self.on_tab(ctx).await, KeyEventType::Backspace => self.on_backspace(ctx).await, KeyEventType::CarriageReturn => self.on_carriage_return(ctx).await, + KeyEventType::CtrlT | KeyEventType::CtrlX | KeyEventType::CtrlV => { + ctx.vim + .echo_message("[igrep] unimplemented ctrl-t/ctrl-x/ctrl-v")?; + Ok(()) + } } } }