Skip to content

Support autocomplete when the caret is in the middle of text #473

@FuJacob

Description

@FuJacob

Summary

Cotabby should support inline autocomplete when the caret is inside existing text, not only when typing at the end of a field.

Problem

Today the suggestion flow is optimized for appending text after the current caret. When the user places the caret in the middle of a paragraph, email, message, or document, suggestions need to respect both the text before the caret and the text after it. Without explicit middle-of-text support, completions can feel unsafe or get suppressed because accepting a suggestion may conflict with the existing trailing text.

Desired behavior

  • If the caret is in the middle of editable text, Cotabby can still generate a useful continuation at the caret.
  • Ghost text renders next to the caret without visually colliding with the existing trailing text.
  • Accepting with Tab inserts only the suggested text at the caret and preserves all existing text after the caret.
  • Suggestions should avoid duplicating or contradicting the trailing text already present after the caret.

Acceptance criteria

  • Detect and allow eligible focus snapshots where trailingText is non-empty.
  • Include bounded trailing context in the request/prompt so the engine knows what follows the caret.
  • Normalize or reject suggestions that simply repeat the existing trailing text.
  • Ensure acceptance/reconciliation inserts at the caret without deleting or moving the trailing text.
  • Add focused tests around request construction, normalization/reconciliation, and acceptance behavior for middle-of-text cases.

Implementation notes

This likely touches SuggestionAvailabilityEvaluator, SuggestionRequestFactory, prompt rendering, SuggestionSessionReconciler, and acceptance/insertion handling. The main tradeoff is safety versus usefulness: we should start conservative, especially in hosts with flaky AX selection/trailing-text reporting, and expand once insertion behavior is proven stable across native AppKit, Chromium, and Electron fields.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    Status
    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions