From e7110efbf639b89878b55e3b325bce4586fe3718 Mon Sep 17 00:00:00 2001 From: cloudhead Date: Thu, 4 Jan 2024 14:02:05 +0100 Subject: [PATCH] term: Fix line width bug with tabs --- radicle-term/src/textarea.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/radicle-term/src/textarea.rs b/radicle-term/src/textarea.rs index a1b5e9f7..da719a0d 100644 --- a/radicle-term/src/textarea.rs +++ b/radicle-term/src/textarea.rs @@ -2,6 +2,8 @@ use crate::{cell::Cell, Constraint, Element, Line, Paint, Size}; /// Default text wrap width. pub const DEFAULT_WRAP: usize = 80; +/// Soft tab replacement for '\t'. +pub const SOFT_TAB: &str = " "; /// Text area. /// @@ -32,7 +34,13 @@ impl TextArea { let mut lines: Vec = Vec::new(); let mut fenced = false; - for line in self.body.content().lines() { + for line in self + .body + .content() + .lines() + // Replace tabs as their visual width cannot be calculated. + .map(|l| l.replace('\t', SOFT_TAB)) + { // Fenced code block support. if line.starts_with("```") { fenced = !fenced;