From e4b5b3f7951aed4fc32f320b9905397621f0a273 Mon Sep 17 00:00:00 2001 From: roboomp Date: Fri, 14 Aug 2026 21:18:40 +0000 Subject: [PATCH] fix(tui): stopped inline code color bleed at soft wraps - Kept ANSI sequences after visible content with the current wrap token so closing resets cannot migrate into discarded whitespace. - Added a regression for a codespan ending exactly at the wrap width. Fixes #8582 --- crates/pi-natives/src/text.rs | 19 ++++++++++++++++++- packages/natives/CHANGELOG.md | 4 ++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/crates/pi-natives/src/text.rs b/crates/pi-natives/src/text.rs index cfcf8a185..22c9ca770 100644 --- a/crates/pi-natives/src/text.rs +++ b/crates/pi-natives/src/text.rs @@ -1000,7 +1000,12 @@ fn split_into_tokens_with_ansi(line: &[u16]) -> SmallVec<[Vec; 4]> { if line[i] == ESC && let Some(seq_len) = ansi_seq_len_u16(line, i) { - pending_ansi.extend_from_slice(&line[i..i + seq_len]); + let seq = &line[i..i + seq_len]; + if current.is_empty() { + pending_ansi.extend_from_slice(seq); + } else { + current.extend_from_slice(seq); + } i += seq_len; continue; } @@ -2003,6 +2008,18 @@ mod tests { assert!(second.contains("world")); } + #[test] + fn test_wrap_text_with_ansi_keeps_trailing_color_reset_before_soft_wrap() { + let data = to_u16("plain \x1b[33mcode\x1b[39m next"); + let lines = wrap_text_with_ansi_impl(&data, 10, DEFAULT_TAB_WIDTH); + let actual: Vec = lines + .iter() + .map(|line| String::from_utf16_lossy(line)) + .collect(); + + assert_eq!(actual, ["plain \x1b[33mcode\x1b[39m", "next"]); + } + #[test] fn test_wrap_text_with_ansi_resets_strike_without_resetting_colors() { let data = diff --git a/packages/natives/CHANGELOG.md b/packages/natives/CHANGELOG.md index ed29a1901..0ce10e154 100644 --- a/packages/natives/CHANGELOG.md +++ b/packages/natives/CHANGELOG.md @@ -2,6 +2,10 @@ ## [Unreleased] +### Fixed + +- Fixed inline-code foreground color carrying into plain text when a Markdown codespan ended exactly at a soft-wrap boundary ([#8582](https://github.com/can1357/oh-my-pi/issues/8582)). + ## [17.3.4] - 2026-08-14 ### Added