Skip to content

Commit

Permalink
FilePicker: Allow setting an initial search query
Browse files Browse the repository at this point in the history
This can be used to set an initial query from a register. Global
search will use this and the file picker could also consider allowing
an initial query using this helper.
  • Loading branch information
the-mikedavis committed Jun 5, 2023
1 parent 50fd8fa commit bdcb8c5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 9 additions & 0 deletions helix-term/src/ui/picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ impl<T: Item + 'static> FilePicker<T> {
self
}

pub fn with_line(mut self, line: String, editor: &Editor) -> Self {
self.picker.set_line(line, editor);
self
}

fn current_file(&self, editor: &Editor) -> Option<FileLocation> {
self.picker
.selection()
Expand Down Expand Up @@ -679,6 +684,10 @@ impl<T: Item> Picker<T> {
}
EventResult::Consumed(None)
}

pub fn set_line(&mut self, line: String, editor: &Editor) {
self.prompt.set_line(line, editor);
}
}

// process:
Expand Down
6 changes: 5 additions & 1 deletion helix-term/src/ui/prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,15 @@ impl Prompt {
}

pub fn with_line(mut self, line: String, editor: &Editor) -> Self {
self.set_line(line, editor);
self
}

pub fn set_line(&mut self, line: String, editor: &Editor) {
let cursor = line.len();
self.line = line;
self.cursor = cursor;
self.recalculate_completion(editor);
self
}

pub fn line(&self) -> &String {
Expand Down

0 comments on commit bdcb8c5

Please sign in to comment.