Skip to content

Implement in-editor search-and-replace (Cmd-F/Cmd-H) for text editors #4992

@hernanmd

Description

@hernanmd

Problem Description

Glamorous Toolkit's text editors (used for methods, playgrounds, etc.) lack a standard in-editor search-and-replace function. Cmd-F (find) and Cmd-H (replace) shortcuts do not work within the editor widget, unlike in conventional IDEs like VS Code or traditional Smalltalk browsers. Spotter provides a global search, but it does not address local in-editor text-editing needs.

Use Case Where Spotter/Refactorings Fail

Consider editing a large Pillar markup file (e.g., a GT book chapter with 500+ lines of mixed prose, code snippets, and @references). I need to perform a bulk text replacement: change all instances of oldMethodName to newMethodName only within inline code blocks (e.g., `oldMethodName` to `newMethodName`), without affecting similar text in prose or headings.

  • Why Spotter fails: Spotter is global and semantic (methods, senders, etc.), so it cannot target literal text spans in a single editor buffer. It jumps to method definitions but ignores non-semantic markup.
  • Why refactorings fail: RB refactorings (rename method/class) operate on AST-level symbols, not raw text. Pillar's inline code is treated as plain text, not executable Pharo code, so no symbol resolution occurs. Regex-based global renames (via Spotter or external tools) risk over-matching across files.
  • Current workflow: Manual selection/copy-paste or external editor switching disrupts GT's live environment flow. For 50+ occurrences, this takes 10-20 minutes per file.

Expected Behavior

  • Cmd-F: Open a floating search bar at the editor top with regex support, next/prev buttons, and case sensitivity toggle.
  • Cmd-H: Extend to find-replace pane (search + replace fields, replace/replace-all).
  • Match VS Code-style: Incremental highlighting, multi-line regex, selection preservation.
  • Integrate with GT styling: Search results as text attributes (e.g., yellow background).

Proposed Implementation Sketch

Extend BrEditor:

BrEditor >> gtSpotterSearchFor: aStep 
	"Wire Cmd-F to local Spotter-like search"
	^ GtSearchTextEditorElement forTextEditor: self
  • Add GtInEditorSearchElement as a layout overlay.
  • Bind via BrTextEditorKeymap (macOS: Cmd-F/H, Win/Linux: Ctrl-F/H).
  • Use a BrTextFindReplacer for logic (extend from existing text ops).

Priority

High for users editing docs/markdown/large texts (Pillar, JSON configs, shaders). Complements Spotter/refactorings without overlap.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions