Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
term: Fix line width bug with tabs
cloudhead committed 2 years ago
commit e7110efbf639b89878b55e3b325bce4586fe3718
parent 91684cc9ca43362db0e546674d53a6322dda039e
1 file changed +9 -1
modified 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<String> = 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;