Repository navigation
Conversation
truncatePath measured and cut paths in bytes. A path with multi-byte characters could be cut in the middle of a rune, which rendered invalid UTF-8, and it was cut shorter than the width allowed. It now uses toolcommon.TruncateTextLeft, as the file picker does, and escapes line breaks first with the file picker's pathEscaper so a path stays on one line. Signed-off-by: Christopher Pruijsen <christopher.pruijsen@gmail.com>
aheritier
left a comment
There was a problem hiding this comment.
One blocking issue inline: paths containing tabs can overflow their column budget and lose the suffix this change is meant to preserve.
| return "…" + path[len(path)-(maxLen-1):] | ||
| // truncatePath shortens a path to fit within maxWidth display columns, prefixing with "…" when truncated. | ||
| func truncatePath(path string, maxWidth int) string { | ||
| return toolcommon.TruncateTextLeft(pathEscaper.Replace(path), maxWidth) |
There was a problem hiding this comment.
[blocking] Escape tabs before measuring the path. With a width of 28, a / followed by a tab and 27 ASCII letters now passes the fit check: ansi.StringWidth doesn't count the tab, but Lip Gloss expands it to four spaces when session_browser.go:638 styles the row. The path renders at 32 columns, so a full row gets clipped from the right (scrollview.go:429), losing the path suffix. The old byte cut dropped the tab and kept all 27 letters. Please add a regression test that checks the styled result fits and retains the tail.
There was a problem hiding this comment.
Fixed in 13ad920. Tabs are escaped before the width check, and the test uses your case.
|
Please mark this PR ready for review once you’ve addressed the requested changes. Thanks! |
Signed-off-by: Christopher Pruijsen <christopher.pruijsen@gmail.com>
Problem
truncatePathinpkg/tui/dialog/working_dir_picker.gomeasured and cut paths in bytes. The session browser, the/contextdialog and the working directory picker use it. A path with multi-byte characters could be cut in the middle of a rune, so the row rendered invalid UTF-8. For example, the session browser showed"…\xa3目录/子目录/第二层"for a session in/home/user/项目/文档与资料/长期保存的归档目录/子目录/第二层. Paths with accented letters were also cut shorter than the row allowed, because each such letter is two bytes but one column.Fix
truncatePathnow callstoolcommon.TruncateTextLeft, the width-aware helper that the file picker has used since fix(tui): truncate the file picker's directory by display width #5026. It keeps the end of the path behind the ellipsis.pathEscaper, also from fix(tui): truncate the file picker's directory by display width #5026. Lip Gloss expands a tab to four spaces after the width is measured, so an unescaped tab could push the row past its width.lipgloss.Widthmeasures only the widest line, so without the escape a directory name with a line break could split the row. ASCII paths with no line break are cut exactly as before.TestTruncatePathKeepsValidUTF8checks the exact result for a CJK path at eight widths.TestTruncatePathMeasuresDisplayWidthchecks that a path with accented letters that fits is not cut, and that an ASCII path is cut as before. Both tests fail before the fix.TestTruncatePathKeepsOneLinechecks that a path with\nor\rstays on one line.