From 725e6784abaa2da2e55d557133511d160af787ff Mon Sep 17 00:00:00 2001 From: alice pellerin Date: Wed, 18 Mar 2026 15:39:37 -0500 Subject: [PATCH] preview bytes under cursor when replacing --- src/app/widget.rs | 19 ++++++++++++++++++- src/edit_action.rs | 1 + src/main.rs | 2 ++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/app/widget.rs b/src/app/widget.rs index b8e9cb3..1c3a8e5 100644 --- a/src/app/widget.rs +++ b/src/app/widget.rs @@ -78,7 +78,7 @@ mod hex { use itertools::{Itertools, repeat_n}; use ratatui::{style::{Color, Style, Stylize}, text::Span}; - use crate::{BYTES_PER_CHUNK, BYTES_PER_LINE, CHUNKS_PER_LINE, app::{App, Mode}, cardinality::HasCardinality, cursor::InCursor, custom_greys::CustomGreys, empty_span::empty_span}; + use crate::{BYTES_PER_CHUNK, BYTES_PER_LINE, CHUNKS_PER_LINE, app::{App, Mode, PartialAction}, cardinality::HasCardinality, cursor::InCursor, custom_greys::CustomGreys, empty_span::empty_span}; impl App { pub fn render_chunks( @@ -189,6 +189,23 @@ mod hex { &self, address: usize, byte: u8 + ) -> Span<'static> { + if self.partial_action == Some(PartialAction::Replace) && + self.cursor.contains(address).is_some() + { + let replaced_byte = self.partial_replace.unwrap_or(0) << 4; + + self.render_byte_without_replace_preview(address, replaced_byte) + .fg(Color::Black) + } else { + self.render_byte_without_replace_preview(address, byte) + } + } + + fn render_byte_without_replace_preview( + &self, + address: usize, + byte: u8 ) -> Span<'static> { const SPAN_FOR_BYTE: [Span; u8::CARDINALITY] = create_byte_lookup_table(); diff --git a/src/edit_action.rs b/src/edit_action.rs index cdac870..e741eff 100644 --- a/src/edit_action.rs +++ b/src/edit_action.rs @@ -1,6 +1,7 @@ use std::cmp::min; use crate::{app::App, cursor::Cursor}; +#[derive(Debug)] pub enum EditAction { Delete { cursor: Cursor, diff --git a/src/main.rs b/src/main.rs index f1d61c8..77da572 100644 --- a/src/main.rs +++ b/src/main.rs @@ -69,6 +69,8 @@ fn main() { ratatui::restore(); + // dbg!(app.edit_history); + for log in app.logs { println!("{log}"); }