Skip to content

RightLayout does not work in Electron apps (Cursor, VS Code) #50

@lkladnit

Description

@lkladnit

Problem

RightLayout does not work in Electron-based apps (tested with Cursor IDE). Both auto-correction and manual hotkey correction fail silently.

Manual hotkey: selecting text and double-tapping Option clears the selection but no correction happens.

Auto-correction: typing in the wrong layout produces no correction as you type.

Native macOS apps (TextEdit, Notes) work correctly.

Environment

  • macOS (Apple Silicon)
  • RightLayout v1.2
  • Cursor IDE (Electron/Chromium-based)
  • Accessibility and Input Monitoring permissions granted

Root Cause Analysis

Reviewed the source code in EventMonitor.swift (handleHotkeyPress). The manual hotkey tries 5 strategies in order:

  1. Existing cycling state — N/A on first press
  2. Pending suggestion — N/A (no auto-correction happened)
  3. snapshotSelectionForManualAction()fails: Electron apps don't expose selected text properly via AXUIElement
  4. inputSession.typedTokenempty: Electron's input handling doesn't feed the event tap the same way native apps do
  5. Clipboard fallback (getSelectedTextViaClipboard) — gated: requires selectionIntentState.isActive(), which checks for an AX selection notification within 3 seconds. Electron apps don't fire these AX notifications, so the gate never opens

The clipboard fallback code (strategy 5) would work if it were allowed to run — the infrastructure is already there.

Suggested Fix

For apps where AX selection reading is unavailable (Electron, Chromium-based), bypass the selectionIntentState guard and attempt the clipboard fallback directly. For example:

// Current (too restrictive):
guard hostProfile.allowsManualSelectionClipboardFallback,
      selectionIntentState.isActive(at: timeProvider.now) else { return }

// Proposed (allow fallback when AX selection failed):
guard hostProfile.allowsManualSelectionClipboardFallback else { return }
// selectionIntentState check is useful for native apps but blocks Electron apps entirely

Alternatively, maintain a list of known Electron bundle IDs (e.g. com.todesktop.*, com.electron.*, com.microsoft.VSCode) and skip the selectionIntentState gate for those.

Steps to Reproduce

  1. Open Cursor IDE (or VS Code)
  2. Type ghbdtn (Russian word "привет" typed in English layout)
  3. Observe: no auto-correction happens
  4. Select the text, double-tap Right Option
  5. Observe: selection clears, text remains unchanged

Expected Behavior

  • Auto-correction should convert ghbdtnпривет as you type
  • Manual hotkey should convert selected text between EN/RU/HE alternatives

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions