From c411d70a57be2371299bddc2f9eb1aeb973699f8 Mon Sep 17 00:00:00 2001 From: gibbz00 Date: Sat, 1 Jul 2023 21:24:02 +0200 Subject: [PATCH] Fix: #7502 --- helix-core/src/register.rs | 6 +++--- helix-view/src/info.rs | 29 ++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/helix-core/src/register.rs b/helix-core/src/register.rs index df68a75943e6..e196611102ff 100644 --- a/helix-core/src/register.rs +++ b/helix-core/src/register.rs @@ -1,6 +1,6 @@ use std::collections::HashMap; -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct Register { name: char, values: Vec, @@ -36,9 +36,9 @@ impl Register { } /// Currently just wraps a `HashMap` of `Register`s -#[derive(Debug, Default)] +#[derive(Debug, Clone, Default)] pub struct Registers { - inner: HashMap, + pub inner: HashMap, } impl Registers { diff --git a/helix-view/src/info.rs b/helix-view/src/info.rs index 1503e855e362..e81b8a4d17ec 100644 --- a/helix-view/src/info.rs +++ b/helix-view/src/info.rs @@ -61,7 +61,7 @@ impl Info { .map(|(ch, reg)| { let content = reg .read() - .get(0) + .last() .and_then(|s| s.lines().next()) .unwrap_or_default(); (ch.to_string(), content) @@ -73,3 +73,30 @@ impl Info { infobox } } + +#[cfg(test)] +mod tests { + use super::*; + use helix_core::register::Register; + use once_cell::sync::Lazy; + + const REGISTER_VALUE_1_MOCK: &str = "value_1"; + const REGISTER_VALUE_2_MOCK: &str = "value_2"; + static REGISTERS_MOCK: Lazy = Lazy::new(|| Registers { + inner: [( + '/', + Register::new_with_values('/', vec![REGISTER_VALUE_1_MOCK.to_string()]), + )] + .into(), + }); + + #[test] + fn infobox_shows_latest_value() { + let mut registers = (*REGISTERS_MOCK).clone(); + registers.push('/', REGISTER_VALUE_2_MOCK.to_string()); + + assert!(Info::from_registers(®isters) + .text + .contains(REGISTER_VALUE_2_MOCK)); + } +}