Skip to content

feat: improve CodeMirror quick tools modifier support#2435

Open
deadlyjack wants to merge 3 commits into
mainfrom
ajit/fix-quicktools
Open

feat: improve CodeMirror quick tools modifier support#2435
deadlyjack wants to merge 3 commits into
mainfrom
ajit/fix-quicktools

Conversation

@deadlyjack

Copy link
Copy Markdown
Member

Adds CodeMirror-aware quick tools handling for modifier text input, navigation keys, shift selection, and shortcut command resolution, with focused editor tests covering the new behavior. Also cleans up the advanced HTTP plugin config entry in package.json.

Adds CodeMirror-aware quick tools handling for modifier text input, navigation keys, shift selection, and shortcut command resolution, with focused editor tests covering the new behavior. Also cleans up the advanced HTTP plugin config entry in package.json.
@greptile-apps

greptile-apps Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR introduces CodeMirror-native handling for quick tools modifier keys, adding new modules for text input interception, navigation command dispatch, shift/multi-cursor selection, and shortcut combo resolution. It also refactors the touch selection controller to support both shift-extend and multi-cursor (Ctrl/Meta) pointer interactions.

  • New CM extension modules (quickToolsModifierInput.ts, quickToolsModifierKeys.ts, quickToolsNavigation.ts, shiftSelection.ts) wire quick-tool modifier state into CodeMirror's input and keybinding pipelines; state cleanup is extracted into quickToolsState.js.
  • shiftClickSelection default flipped from false to true, making shift-click range extension opt-out for all existing users whose settings have never been explicitly saved.
  • package.json removes the explicit ANDROIDBLACKLISTSECURESOCKETPROTOCOLS blacklist from cordova-plugin-advanced-http, delegating TLS protocol negotiation entirely to the OS (covered separately in existing review comments).

Confidence Score: 4/5

The new CM extension modules are well-structured and well-tested, but quickTools.js carries two unresolved defects from prior review rounds that directly affect modifier-key behaviour at runtime.

The modifier state is not reliably reset after non-arrow quick-tool key presses, and the module-level input variable is overwritten inside the CM inputHandler callback — both flagged in prior review threads and neither addressed in this revision. Those paths are exercised on every modifier+key press, so they represent a real correctness risk for the feature this PR is built around.

src/handlers/quickTools.js warrants the closest look — the modifier-reset and input-mutation issues from prior reviews still live there. src/lib/editorManager.js has a minor unconditional preventDefault in the new mousedown handler.

Important Files Changed

Filename Overview
src/cm/quickToolsModifierInput.ts New module that registers a CM inputHandler extension backed by a module-level singleton handler; clean design, well-guarded setter.
src/cm/quickToolsModifierKeys.ts New shortcut normalisation and command-lookup module; modifier ordering is handled in two places (getQuickToolCombo and normalizeShortcutCombo) which can silently diverge (flagged in a prior review thread).
src/cm/quickToolsNavigation.ts New navigation dispatch module with comprehensive command tables for plain/shift/ctrl/meta movement and delete; well-tested and correctly falls back through runScopeHandlers before the command table.
src/cm/shiftSelection.ts New helpers for resolving shift-extend and multi-cursor active states from both physical events and quick-tools state; logic is clean and well-tested.
src/cm/touchSelectionMenu.js Generalises shift-only selection into a pointer-selection session supporting both shift-extend and multi-cursor (Ctrl/Meta); addPointerSelectionRange correctly places cursor or range depending on extend flag.
src/handlers/quickTools.js Central handler wired to CM inputHandler and key dispatch; prior reviews flagged modifier state not reset after non-arrow keys and the input module-variable side-effect in the CM callback — both remain unaddressed.
src/handlers/quickToolsState.js New utility module for clearing modifier state, button feedback, and action-stack entries; logic is straightforward and well-tested.
src/lib/editorManager.js Adds multiCursorSelectionExtension and quickToolsModifierInputExtension; new mousedown handler correctly blocks shift-extend when setting is disabled, but calls event.preventDefault() unconditionally even when posAtCoords returns null.
src/lib/settings.js Default for shiftClickSelection flipped from false to true — behavioral change for all existing users whose preference was never explicitly saved.
src/handlers/quickToolsInit.js Extracts clearTouchFeedback helper; behaviour is preserved identically from original touchcancel logic.
src/test/editor.tests.js Adds extensive focused editor tests covering arrow/shift/ctrl navigation, multi-cursor selection, shift text mapping, and command resolution — good coverage for the new CM behaviour.
src/test/sanity.tests.js Adds sanity tests for clearModifierState, clearQuickToolsButtonFeedback, and removeActionStackEntries; correctly validates the extracted state utilities.
package.json Removes ANDROIDBLACKLISTSECURESOCKETPROTOCOLS from cordova-plugin-advanced-http, silently dropping the SSLv3/TLSv1 protocol blacklist (security concern raised in prior review).
src/cm/lineNumberSelection.ts Adds shiftClickSelection option to handleLineNumberClick so line-gutter shift-click respects the same setting as the main editor area.
src/cm/mainEditorExtensions.ts Adds multiCursorSelectionExtension and quickToolsModifierInputExtension slots to the extension options interface and push list.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Quick Tool Button Press] --> B{action type}
    B -->|modifier key| C[actions: state + events]
    B -->|key code| D[getKeys + keyCombination]
    C --> E{Any modifier active?}
    E -->|yes, CM editor focused| F[editor.focus]
    E -->|yes, other input| G[$input.focus]
    D --> H[runCodeMirrorQuickToolKey]
    H --> I{isCodeMirrorEditorInput?}
    I -->|yes| J[runQuickToolKey / runScopeHandlers]
    I -->|no| K[getInput.dispatchEvent keydown]
    J --> L{runScopeHandlers handled?}
    L -->|yes| M[view.focus / return true]
    L -->|no| N[getFallbackCommand lookup]
    N --> O{command found?}
    O -->|yes| P[command view + view.focus]
    O -->|no| Q[return false]
    M --> R[shouldResetKeys? resetKeys]
    P --> R
    K --> R
    S[Virtual keyboard input] --> T[CM inputHandler: handleCodeMirrorQuickToolsTextInput]
    T --> U{Any modifier active?}
    U -->|no| V[return false - normal insert]
    U -->|shift only| W[resetKeys + replaceSelection with mapped char]
    U -->|ctrl/alt/meta| X[findQuickToolCommand in registry]
    X --> Y{command found?}
    Y -->|yes| Z[executeCommand + view]
    Y -->|no| AA[dispatchEvent keydown on contentDOM]
    Z --> AB[resetKeys + return true]
    AA --> AB
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A[Quick Tool Button Press] --> B{action type}
    B -->|modifier key| C[actions: state + events]
    B -->|key code| D[getKeys + keyCombination]
    C --> E{Any modifier active?}
    E -->|yes, CM editor focused| F[editor.focus]
    E -->|yes, other input| G[$input.focus]
    D --> H[runCodeMirrorQuickToolKey]
    H --> I{isCodeMirrorEditorInput?}
    I -->|yes| J[runQuickToolKey / runScopeHandlers]
    I -->|no| K[getInput.dispatchEvent keydown]
    J --> L{runScopeHandlers handled?}
    L -->|yes| M[view.focus / return true]
    L -->|no| N[getFallbackCommand lookup]
    N --> O{command found?}
    O -->|yes| P[command view + view.focus]
    O -->|no| Q[return false]
    M --> R[shouldResetKeys? resetKeys]
    P --> R
    K --> R
    S[Virtual keyboard input] --> T[CM inputHandler: handleCodeMirrorQuickToolsTextInput]
    T --> U{Any modifier active?}
    U -->|no| V[return false - normal insert]
    U -->|shift only| W[resetKeys + replaceSelection with mapped char]
    U -->|ctrl/alt/meta| X[findQuickToolCommand in registry]
    X --> Y{command found?}
    Y -->|yes| Z[executeCommand + view]
    Y -->|no| AA[dispatchEvent keydown on contentDOM]
    Z --> AB[resetKeys + return true]
    AA --> AB
Loading

Reviews (3): Last reviewed commit: "fixed stuffs" | Re-trigger Greptile

Comment thread src/handlers/quickTools.js Outdated
Comment thread src/handlers/quickTools.js
Comment thread src/cm/quickToolsModifierKeys.ts Outdated
- Add CodeMirror-aware quick-tools modifier input, navigation, shift tap selection, and multi-cursor handling.
- Keep editor focus/caret visible while quick-tools modifiers are active.
- Hide unreliable Shift tap/click setting for now.
- Clear stuck quick-toolbar modifier/active state around search open/close.
- Add focused tests for modifier combos, pointer selection, multi-cursor, and search cleanup.
@deadlyjack

This comment was marked as outdated.

- addressed the greptile review regarding: combo normalization and mutation thing
- Fixed non-arrow quick-tool keys leaving modifier state active after dispatch.
- Fixed rapid quick-tool taps leaving orphan `.active` feedback on symbol buttons
- Restored `shiftClickSelection` in editor settings
- Made disabling shiftClickSelection actually block Shift pointer/range selection, including line numbers.
- Updated editor tests for the restored Shift selection behavior.
- Added old-WebView settings switch fallback
@bajrangCoder

This comment was marked as outdated.

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

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

2 participants