summaryrefslogtreecommitdiff
path: root/helix-term/src/commands.rs
diff options
context:
space:
mode:
authorGokul Soumya2021-08-12 07:00:42 +0000
committerGitHub2021-08-12 07:00:42 +0000
commitd84f8b5fdef71da87ee108db07ba1167fc6a769b (patch)
tree057f87cb1107aae3eb966ff3e228b15d3e36ff2e /helix-term/src/commands.rs
parent7d51805e94a461834ce34e0829da5859d1f9db32 (diff)
Show file preview in split pane in fuzzy finder (#534)
* Add preview pane for fuzzy finder * Fix picker preview lag by caching * Add picker preview for document symbols * Cache picker preview per document instead of view * Use line instead of range for preview doc * Add picker preview for buffer picker * Fix render bug and refactor picker * Refactor picker preview rendering * Split picker and preview and compose The current selected item is cloned on every event, which is undesirable * Refactor out clones in previewed picker * Retrieve doc from editor if possible in filepicker * Disable syntax highlight for picker preview Files already loaded in memory have syntax highlighting enabled * Ignore directory symlinks in file picker * Cleanup unnecessary pubs and derives * Remove unnecessary highlight from file picker * Reorganize buffer rendering * Use normal picker for code actions * Remove unnecessary generics and trait impls * Remove prepare_for_render and make render mutable * Skip picker preview if screen small, less padding
Diffstat (limited to 'helix-term/src/commands.rs')
-rw-r--r--helix-term/src/commands.rs33
1 files changed, 26 insertions, 7 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 2b1b859b..0d118dbc 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -27,7 +27,7 @@ use movement::Movement;
use crate::{
compositor::{self, Component, Compositor},
- ui::{self, Picker, Popup, Prompt, PromptEvent},
+ ui::{self, FilePicker, Picker, Popup, Prompt, PromptEvent},
};
use crate::job::{self, Job, Jobs};
@@ -2212,7 +2212,7 @@ fn file_picker(cx: &mut Context) {
fn buffer_picker(cx: &mut Context) {
let current = view!(cx.editor).doc;
- let picker = Picker::new(
+ let picker = FilePicker::new(
cx.editor
.documents
.iter()
@@ -2234,6 +2234,15 @@ fn buffer_picker(cx: &mut Context) {
|editor: &mut Editor, (id, _path): &(DocumentId, Option<PathBuf>), _action| {
editor.switch(*id, Action::Replace);
},
+ |editor, (id, path)| {
+ let doc = &editor.documents.get(*id)?;
+ let &view_id = doc.selections().keys().next()?;
+ let line = doc
+ .selection(view_id)
+ .primary()
+ .cursor_line(doc.text().slice(..));
+ Some((path.clone()?, Some(line)))
+ },
);
cx.push_layer(Box::new(picker));
}
@@ -2287,7 +2296,7 @@ fn symbol_picker(cx: &mut Context) {
}
};
- let picker = Picker::new(
+ let picker = FilePicker::new(
symbols,
|symbol| (&symbol.name).into(),
move |editor: &mut Editor, symbol, _action| {
@@ -2297,10 +2306,15 @@ fn symbol_picker(cx: &mut Context) {
if let Some(range) =
lsp_range_to_range(doc.text(), symbol.location.range, offset_encoding)
{
- doc.set_selection(view.id, Selection::single(range.to(), range.from()));
+ doc.set_selection(view.id, Selection::single(range.anchor, range.head));
align_view(doc, view, Align::Center);
}
},
+ move |_editor, symbol| {
+ let path = symbol.location.uri.to_file_path().unwrap();
+ let line = Some(symbol.location.range.start.line as usize);
+ Some((path, line))
+ },
);
compositor.push(Box::new(picker))
}
@@ -2332,6 +2346,7 @@ pub fn code_action(cx: &mut Context) {
response: Option<lsp::CodeActionResponse>| {
if let Some(actions) = response {
let picker = Picker::new(
+ true,
actions,
|action| match action {
lsp::CodeActionOrCommand::CodeAction(action) => {
@@ -2703,7 +2718,7 @@ fn goto_impl(
editor.set_error("No definition found.".to_string());
}
_locations => {
- let picker = ui::Picker::new(
+ let picker = FilePicker::new(
locations,
move |location| {
let file: Cow<'_, str> = (location.uri.scheme() == "file")
@@ -2728,6 +2743,11 @@ fn goto_impl(
move |editor: &mut Editor, location, action| {
jump_to(editor, location, offset_encoding, action)
},
+ |_editor, location| {
+ let path = location.uri.to_file_path().unwrap();
+ let line = Some(location.range.start.line as usize);
+ Some((path, line))
+ },
);
compositor.push(Box::new(picker));
}
@@ -3729,8 +3749,7 @@ fn keep_primary_selection(cx: &mut Context) {
let (view, doc) = current!(cx.editor);
let range = doc.selection(view.id).primary();
- let selection = Selection::single(range.anchor, range.head);
- doc.set_selection(view.id, selection);
+ doc.set_selection(view.id, Selection::single(range.anchor, range.head));
}
fn completion(cx: &mut Context) {