Skip to content

Commit a26c13a

Browse files
committed
feat: Add context-aware cursor rendering for Latin vs Arabic text
Implements Phase 3 of the dual-cursor system architecture. This modifies the cursor rendering to detect script type and apply appropriate visual treatment: - Latin/non-connected scripts (focused): Opaque text with solid background (restores standard Vim block cursor behavior) - Arabic/connected scripts (focused): Transparent text with solid background (preserves visual character connections in RTL) - Any script (unfocused): Transparent text with outline only Changes: - Import detectScriptTypeWithContext() from script-detection module - Add script detection and focus state checking in measureCursor() - Set partial parameter based on script type and focus state This addresses maintainer feedback on #248 about restoring standard Vim cursor behavior for Latin text while maintaining special handling for Arabic connected characters. Performance: Adds single O(1) script detection per cursor render. Tested: ✅ Latin letters show white text in cursor (opaque) Tested: ✅ Arabic letters are invisible in cursor (transparent)
1 parent 1b68e0a commit a26c13a

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

src/block-cursor.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { SelectionRange, Prec } from "@codemirror/state"
22
import { ViewUpdate, EditorView, Direction } from "@codemirror/view"
33
import { CodeMirror } from "."
4+
import { detectScriptTypeWithContext } from "./script-detection"
45

56
import * as View from "@codemirror/view"
67
// backwards compatibility for old versions not supporting getDrawSelectionConfig
@@ -271,11 +272,23 @@ function measureCursor(cm: CodeMirror, view: EditorView, cursor: SelectionRange,
271272
}
272273

273274
let h = (pos.bottom - pos.top);
275+
276+
// Context-aware cursor rendering based on script type and focus state
277+
const scriptDetection = detectScriptTypeWithContext(view, head);
278+
const isFocused = view.hasFocus;
279+
280+
// Use transparent text for:
281+
// - Arabic/connected scripts (preserves visual character connections)
282+
// - Unfocused state (renders as outline only)
283+
// Use opaque text for:
284+
// - Latin/non-connected scripts when focused (standard Vim block cursor)
285+
const useTransparentText = !isFocused || scriptDetection.requiresSpecialCursor;
286+
274287
return new Piece((left - base.left)/view.scaleX, (pos.top - base.top + h * (1 - hCoeff))/view.scaleY, h * hCoeff/view.scaleY,
275288
charWidth/view.scaleX,
276289
style.fontFamily, style.fontSize, style.fontWeight, style.color,
277290
primary ? "cm-fat-cursor cm-cursor-primary" : "cm-fat-cursor cm-cursor-secondary",
278-
letter, true) // Always use transparent letter to preserve RTL character connections
291+
letter, useTransparentText)
279292
} else {
280293
return null;
281294
}

0 commit comments

Comments
 (0)