From 3dbad0442fc3038dd0b0f6bd07ba0e40d2d92000 Mon Sep 17 00:00:00 2001 From: Saber Haj Rabiee Date: Fri, 24 Jun 2022 08:14:48 -0700 Subject: [PATCH] fixes showing the last prompt on empty input (#2870) --- helix-core/src/register.rs | 4 ++++ helix-term/src/ui/prompt.rs | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/helix-core/src/register.rs b/helix-core/src/register.rs index 7fa34644b..1cff77ba3 100644 --- a/helix-core/src/register.rs +++ b/helix-core/src/register.rs @@ -73,6 +73,10 @@ impl Registers { self.read(name).and_then(|entries| entries.first()) } + pub fn last(&self, name: char) -> Option<&String> { + self.read(name).and_then(|entries| entries.last()) + } + pub fn inner(&self) -> &HashMap { &self.inner } diff --git a/helix-term/src/ui/prompt.rs b/helix-term/src/ui/prompt.rs index beba8ce9a..55b08032d 100644 --- a/helix-term/src/ui/prompt.rs +++ b/helix-term/src/ui/prompt.rs @@ -443,7 +443,7 @@ impl Prompt { let input: Cow = if self.line.is_empty() { // latest value in the register list self.history_register - .and_then(|reg| cx.editor.registers.first(reg)) + .and_then(|reg| cx.editor.registers.last(reg)) .map(|entry| entry.into()) .unwrap_or_else(|| Cow::from("")) } else { @@ -522,7 +522,7 @@ impl Component for Prompt { let input: Cow = if self.line.is_empty() { // latest value in the register list self.history_register - .and_then(|reg| cx.editor.registers.first(reg).cloned()) + .and_then(|reg| cx.editor.registers.last(reg).cloned()) .map(|entry| entry.into()) .unwrap_or_else(|| Cow::from("")) } else {