Skip to content

feat(editor): add incremental forward and reverse search - #184

Merged
owainlewis merged 1 commit into
mainfrom
codex/issue-29-incremental-search
Sep 9, 2026
Merged

feat(editor): add incremental forward and reverse search#184
owainlewis merged 1 commit into
mainfrom
codex/issue-29-incremental-search

Conversation

@owainlewis

Copy link
Copy Markdown
Owner

C-s and C-r now open incremental literal search in either direction.
Typing and prompt paste update the query, move to a visible match, and leave buffer text and history intact.
Repeat advances through overlapping matches and wraps once, Enter accepts, and Escape/C-g restores the original point and both scroll offsets.
Cancellation also clears a pending clipboard prefix.
No-match feedback preserves the last useful point, and other editor commands accept search before dispatching normally.

The matcher streams Rope characters with memory proportional to query length instead of copying the buffer on each keystroke.
The current match gets a distinct background across complete graphemes, horizontal scrolling, and resize.
Existing named literal search and repeat aliases remain available; search-backward is also registered.

Verification: 408 unit tests pass (four existing diagnostics ignored), formatting, strict Clippy across all targets, and release build pass.
The release PTY workflow covers forward/reverse search, match colour, repeat/wrap, no-match recovery, cancellation including pending clipboard prefixes, accept, literal prompt paste, command dispatch, combining-character matches, save, quit, and shell restoration.
The existing release diagnostic completed 50 searches of a roughly 1.8 MB buffer in 273 ms.
Independent review approved after its cancellation finding was reproduced and fixed.
Eleven of thirteen terminal tests pass locally; the two unchanged redirected-input tests encounter the documented sandbox restrictions and run in macOS CI.

Closes #29.

@greptile-apps

greptile-apps Bot commented Sep 9, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds incremental forward and reverse literal search while retaining named immediate-search and repeat commands.

  • Adds a streaming, query-sized KMP matcher over Rope characters with forward, reverse, overlap, and wrap support.
  • Introduces transient incremental-search state with query editing, paste, repeat, acceptance, cancellation, and full View restoration.
  • Adds C-s/C-r bindings and optional-argument search-forward/search-backward commands.
  • Highlights the active match across complete graphemes and horizontally clipped rendering.
  • Updates architecture, user documentation, planning notes, and focused tests.

Confidence Score: 5/5

The PR appears safe to merge with no concrete correctness, security, or repository-rule violations identified.

Search matching, input lifecycle, command compatibility, View restoration, and match rendering are internally consistent and covered by focused boundary and integration tests; no actionable failure remains.

Important Files Changed

Filename Overview
src/search.rs Adds streaming forward/reverse literal matching and incremental-search state with overlap and wrap handling.
src/app.rs Integrates search input, paste, cancellation, acceptance, command dispatch, and rendering into application state.
src/renderer.rs Adds active-match styling using absolute character ranges and complete-grapheme rendering.
src/command_registry.rs Makes forward search argument-optional and registers the reverse-search command.
src/keymap.rs Binds C-s and C-r to forward and reverse incremental search.
src/buffer.rs Replaces whole-buffer forward-search materialization with the shared streaming matcher.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[C-s / C-r or named command] --> B{Literal argument supplied?}
    B -- Yes --> C[Run immediate directional search]
    B -- No --> D[Create IncrementalSearch]
    D --> E{Input}
    E -- Character / paste / backspace --> F[Update query]
    F --> G[Stream Rope through directional KMP]
    G --> H{Match found?}
    H -- Yes --> I[Move View point and highlight range]
    H -- No --> J[Keep last useful point and show no match]
    E -- C-s / C-r --> K[Advance directionally with overlap and wrap]
    K --> G
    E -- Enter / other command --> L[Accept search]
    E -- Escape / C-g --> M[Restore original point and scroll]
    L --> N[Dispatch other command when applicable]
Loading

Reviews (1): Last reviewed commit: "feat(editor): add incremental forward an..." | Re-trigger Greptile

@owainlewis
owainlewis merged commit 8fd7847 into main Sep 9, 2026
2 checks passed
@owainlewis
owainlewis deleted the codex/issue-29-incremental-search branch September 9, 2026 08:41
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.

[v0.3] Add incremental search

1 participant