Repository navigation
Conversation
- Add search.resultsTruncation: 'start' | 'end' | 'both' | 'off' (default 'start') - Add search.allowedSizeBeforeTruncation (default 1000; regex min 10000) - Wire truncationMode + charsPerLine through Search view, Quick Text Search, Search Editor - Implement modes in TextSearchMatch and align non-rg path (getFileResults) - Add tests for new modes Refs microsoft#273410
|
@microsoft-github-policy-service agree |
There was a problem hiding this comment.
I'm not sure I understand what problem this PR is trying to fix, when we do search we can truncate both beginning or end depending on where the term that was searched for.
Example: searching for interface you can see truncation in all places.

With this change the search results are pretty much impossible to parse

|
shoulders (@shoulders) I see, so this is more like amount of characters of context that you would like to have at the beginning or end of the truncation. Given that we actually truncate today at the beginning and end, having a setting like this will be very confusing. Could you change the PR so that the setting is referring to the amount of characters to the left or right that users would like to have as context with an option of allowing all characters en each direction? And instead of doing |
|
Osvaldo Ortega (@osortega) it is not my PR and my level of programming is not at that level. For me, the most important thing is to disable truncation. The ability to also control the truncation amounts, left and right, is important to have a flexible workflow. |
|
Osvaldo Ortega (@osortega) Why was this closed? |

Summary
Improves readability of search result previews by making truncation behavior configurable.
Adds options to show full lines, truncate from the start, end, or both sides (keeping the match centered).
Keeps default behavior unchanged for existing users.
New Settings
search.resultsTruncation: 'start' | 'end' | 'both' | 'off' (default: 'start')
search.allowedSizeBeforeTruncation: number of characters before truncating (default: 1000; regex searches enforce a minimum of 10000 internally for replace correctness)
Example:
"search.resultsTruncation": "both"
"search.allowedSizeBeforeTruncation": 80
Behavior
start: elides the beginning (“⟪ N characters skipped ⟫”), match remains in view.
end: shows the start, elides the tail with the same elision token.
both: elides both sides to center the match for context.
off: no elision (full line preview; UI may still visually clip).
Scope
Applies to Search view, Quick Text Search, and Search Editor.
Works with both ripgrep and non-rg (in-memory) result paths.
Implementation Notes
Uses existing elision token (unchanged): “⟪ N characters skipped ⟫” to preserve Search Editor offset parsing.
Honors regex replace constraints by using >= 10000 chars per line for regex queries.
Default behavior remains identical to current (truncation at the start).
Test Plan
Unit tests: src/vs/workbench/services/search/test/common/search.test.ts
Manual:
Create a file with a very long single line containing the search term.
Toggle search.resultsTruncation through all options and validate:
start → left elision only
end → trailing elision only
both → both sides elide, match centered
off → full line shown
Adjust search.allowedSizeBeforeTruncation to a small value (e.g., 40) to see clear effects.
Verify in Search view, Quick Text Search (%), and Search Editor.
Release Notes
Fixes #273410