|
|
|
@ -117,6 +117,19 @@ impl Prompt {
|
|
|
|
|
&self.line
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn with_history_register(&mut self, history_register: Option<char>) -> &mut Self {
|
|
|
|
|
self.history_register = history_register;
|
|
|
|
|
self
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub(crate) fn first_history_completion<'a>(
|
|
|
|
|
&'a self,
|
|
|
|
|
editor: &'a Editor,
|
|
|
|
|
) -> Option<Cow<'a, str>> {
|
|
|
|
|
self.history_register
|
|
|
|
|
.and_then(|reg| editor.registers.first(reg, editor))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn recalculate_completion(&mut self, editor: &Editor) {
|
|
|
|
|
self.exit_selection();
|
|
|
|
|
self.completion = (self.completion_fn)(editor, &self.line);
|
|
|
|
@ -480,10 +493,7 @@ impl Prompt {
|
|
|
|
|
let line_area = area.clip_left(self.prompt.len() as u16).clip_top(line);
|
|
|
|
|
if self.line.is_empty() {
|
|
|
|
|
// Show the most recently entered value as a suggestion.
|
|
|
|
|
if let Some(suggestion) = self
|
|
|
|
|
.history_register
|
|
|
|
|
.and_then(|reg| cx.editor.registers.first(reg, cx.editor))
|
|
|
|
|
{
|
|
|
|
|
if let Some(suggestion) = self.first_history_completion(cx.editor) {
|
|
|
|
|
surface.set_string(line_area.x, line_area.y, suggestion, suggestion_color);
|
|
|
|
|
}
|
|
|
|
|
} else if let Some((language, loader)) = self.language.as_ref() {
|
|
|
|
@ -578,8 +588,7 @@ impl Component for Prompt {
|
|
|
|
|
self.recalculate_completion(cx.editor);
|
|
|
|
|
} else {
|
|
|
|
|
let last_item = self
|
|
|
|
|
.history_register
|
|
|
|
|
.and_then(|reg| cx.editor.registers.first(reg, cx.editor))
|
|
|
|
|
.first_history_completion(cx.editor)
|
|
|
|
|
.map(|entry| entry.to_string())
|
|
|
|
|
.unwrap_or_else(|| String::from(""));
|
|
|
|
|
|
|
|
|
|