Skip to content

Commit

Permalink
Fix open action regression for filer provider (#1093)
Browse files Browse the repository at this point in the history
* Fix open action regression for filer provider

Close #1092

* Friendly message for igrep
  • Loading branch information
liuchengxu authored Sep 27, 2024
1 parent f473912 commit 2069bc5
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 0 deletions.
6 changes: 6 additions & 0 deletions autoload/clap/selection.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions autoload/clap/util.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 9 additions & 0 deletions crates/maple_core/src/stdio_server/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ pub enum KeyEventType {
CtrlN,
// <C-P>
CtrlP,
// <C-t>
CtrlT,
// <C-x>
CtrlX,
// <C-v>
CtrlV,
}

pub type ActionEvent = (PluginId, PluginAction);
Expand Down Expand Up @@ -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))),
Expand Down
11 changes: 11 additions & 0 deletions crates/maple_core/src/stdio_server/provider/impls/filer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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,
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions crates/maple_core/src/stdio_server/provider/impls/igrep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
}
}
}
Expand Down

0 comments on commit 2069bc5

Please sign in to comment.