Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show file preview in split pane in fuzzy finder #534

Merged
merged 21 commits into from
Aug 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
7a1dbed
Add preview pane for fuzzy finder
sudormrfbin Jul 30, 2021
ab41e45
Fix picker preview lag by caching
sudormrfbin Jul 31, 2021
c62d5aa
Add picker preview for document symbols
sudormrfbin Jul 31, 2021
5325eea
Cache picker preview per document instead of view
sudormrfbin Jul 31, 2021
6df7cfa
Use line instead of range for preview doc
sudormrfbin Jul 31, 2021
2ed40c2
Add picker preview for buffer picker
sudormrfbin Jul 31, 2021
5785258
Fix render bug and refactor picker
sudormrfbin Jul 31, 2021
42ebb1b
Refactor picker preview rendering
sudormrfbin Aug 1, 2021
bd5c7b5
Split picker and preview and compose
sudormrfbin Aug 1, 2021
29b0757
Refactor out clones in previewed picker
sudormrfbin Aug 2, 2021
3ab2823
Retrieve doc from editor if possible in filepicker
sudormrfbin Aug 3, 2021
a524cd8
Disable syntax highlight for picker preview
sudormrfbin Aug 6, 2021
f902c5f
Ignore directory symlinks in file picker
sudormrfbin Aug 6, 2021
820b85e
Cleanup unnecessary pubs and derives
sudormrfbin Aug 6, 2021
a2e8a33
Remove unnecessary highlight from file picker
sudormrfbin Aug 7, 2021
805c0e0
Reorganize buffer rendering
sudormrfbin Aug 9, 2021
0bb5a13
Merge branch 'master' into fuzzy-finder-preview
sudormrfbin Aug 9, 2021
ecc857b
Use normal picker for code actions
sudormrfbin Aug 10, 2021
014cdd1
Remove unnecessary generics and trait impls
sudormrfbin Aug 11, 2021
bbd5071
Remove prepare_for_render and make render mutable
sudormrfbin Aug 12, 2021
a8d5832
Skip picker preview if screen small, less padding
sudormrfbin Aug 12, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 26 additions & 7 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -2117,7 +2117,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()
Expand All @@ -2139,6 +2139,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));
}
Expand Down Expand Up @@ -2192,7 +2201,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| {
Expand All @@ -2202,10 +2211,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);
sudormrfbin marked this conversation as resolved.
Show resolved Hide resolved
Some((path, line))
},
);
compositor.push(Box::new(picker))
}
Expand Down Expand Up @@ -2237,6 +2251,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) => {
Expand Down Expand Up @@ -2605,7 +2620,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")
Expand All @@ -2630,6 +2645,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));
}
Expand Down Expand Up @@ -3585,8 +3605,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) {
Expand Down
6 changes: 3 additions & 3 deletions helix-term/src/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub trait Component: Any + AnyComponent {
}

/// Render the component onto the provided surface.
fn render(&self, area: Rect, frame: &mut Surface, ctx: &mut Context);
fn render(&mut self, area: Rect, frame: &mut Surface, ctx: &mut Context);

/// Get cursor position and cursor kind.
fn cursor(&self, _area: Rect, _ctx: &Editor) -> (Option<Position>, CursorKind) {
Expand Down Expand Up @@ -152,8 +152,8 @@ impl Compositor {

let area = *surface.area();

for layer in &self.layers {
layer.render(area, surface, cx)
for layer in &mut self.layers {
layer.render(area, surface, cx);
}

let (pos, kind) = self.cursor(area, cx.editor);
Expand Down
4 changes: 2 additions & 2 deletions helix-term/src/ui/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ impl Component for Completion {
self.popup.required_size(viewport)
}

fn render(&self, area: Rect, surface: &mut Surface, cx: &mut Context) {
fn render(&mut self, area: Rect, surface: &mut Surface, cx: &mut Context) {
self.popup.render(area, surface, cx);

// if we have a selection, render a markdown popup on top/below with info
Expand All @@ -228,7 +228,7 @@ impl Component for Completion {
let cursor_pos = (helix_core::coords_at_pos(doc.text().slice(..), cursor_pos).row
- view.first_line) as u16;

let doc = match &option.documentation {
let mut doc = match &option.documentation {
Some(lsp::Documentation::String(contents))
| Some(lsp::Documentation::MarkupContent(lsp::MarkupContent {
kind: lsp::MarkupKind::PlainText,
Expand Down
Loading