vscode
vscode copied to clipboard
BUG: lcut() / rcut() break words incorrectly for non-ASCII text (Search preview, chat titles)
Does this issue occur when all extensions are disabled?: Yes
- VS Code Version: 1.148.0 (
main@ 41004e061e582855eb1e99b6a6e5d52994f661be) - OS Version:
Steps to Reproduce:
- Run the following against
src/vs/base/common/strings.ts:
import { lcut, rcut } from './strings';
rcut('héllo wörld ünï', 7, '…'); // "héllo w…" (cuts inside "wörld")
lcut('héllo wörld ünï', 7, '…'); // "…rld ünï" (cuts inside "wörld")
- In the UI, search for a term on a line containing accented or non-Latin text. The match preview is cut in the middle of a word.
Expected
Cuts happen at real word boundaries, e.g. rcut should not split "wörld" into "w".
Cause
lcut (line ~784) and rcut (line ~814) find word breaks with /\b/g. In JavaScript, \b only treats [A-Za-z0-9_] as word characters, so accented letters and CJK characters count as non-word and produce false break points.
Suggested fix
Use Intl.Segmenter with granularity: 'word' to find boundaries, as editor word operations already do (see #203605).
Impact
lcutbuilds the Search view match preview (searchTreeModel/match.ts).rcuttruncates chat subagent titles (chatSubagentContentPart.ts).