Skip to content

Conversation

@Yonas650
Copy link

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

    • Covers off, end, and both modes in addition to existing behavior.
  • 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

  • New: Control how search results are truncated with search.resultsTruncation and search.allowedSizeBeforeTruncation for improved readability and context.

Fixes #273410

- 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
@Yonas650
Copy link
Author

@microsoft-github-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Search Results - Improve truncation - Show full line, Truncate on the Left or the Right

2 participants