vscode icon indicating copy to clipboard operation
vscode copied to clipboard

BUG: lcut() / rcut() break words incorrectly for non-ASCII text (Search preview, chat titles)

Open mant-raj opened this issue 1 week ago • 0 comments

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version: 1.148.0 (main @ 41004e061e582855eb1e99b6a6e5d52994f661be)
  • OS Version:

Steps to Reproduce:

  1. 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")
  1. 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

  • lcut builds the Search view match preview (searchTreeModel/match.ts).
  • rcut truncates chat subagent titles (chatSubagentContentPart.ts).

mant-raj avatar Nov 18 '26 17:11 mant-raj