Commit 2973aec
committed
Fix cursor rendering for Arabic connected characters
This commit improves the block cursor behavior for Arabic text, where
connected characters were being broken by the cursor overlay.
## Problems Fixed
1. **Character Breaking in Arabic**: The block cursor used an opaque
background that covered characters, breaking visual continuity of
connected Arabic letters. In Arabic, letters change shape based on
their position in a word (isolated/initial/medial/final forms), and
the cursor was disrupting these connections.
2. **Incorrect Width Calculation**: The cursor width was based on the
isolated form of characters placed inside the cursor div, not the
actual rendered width in connected text. This caused misalignment
where narrow connected forms appeared in wide cursor boxes.
3. **Newline Cursor Issues**:
- Wide cursor boxes appeared at end of lines
- In normal mode, cursor could be positioned on newline characters
(inconsistent with Vim behavior where $ positions on last character)
## Solutions Implemented
1. **Transparent Cursor with Outline**: Changed from opaque background
to transparent background with box-shadow outline, allowing underlying
text to show through naturally without breaking character connections.
2. **DOM-Based Width Measurement**: Calculate actual character width by
measuring the rendered glyph using Range.getBoundingClientRect(). This
captures the true width of characters after browser text shaping,
including Arabic contextual forms.
3. **Smart Newline Handling**:
- Use narrow cursor (15% of font size) for newline characters
- In normal mode, automatically adjust cursor position to last real
character when on end-of-line newline (matching Vim $ behavior)
- Preserve cursor on empty lines (consecutive newlines)
## Technical Details
- Added `width` property to Piece class for explicit width control
- Save original DOM position before traversal for accurate measurement
- Use Range API to measure individual character width from text nodes
- Force transparent letter rendering to avoid covering underlying text
- Distinguish between end-of-line newlines and empty line newlines
## Impact
This fixes a major usability issue for Arabic language users, making the
Vim mode cursor behavior work correctly with Arabic's connected writing
system while properly handling complex text shaping.
Fixes visual character breaking in Arabic text editing.1 parent 71919db commit 2973aec
1 file changed
+63
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
| 39 | + | |
38 | 40 | | |
39 | 41 | | |
40 | 42 | | |
| |||
47 | 49 | | |
48 | 50 | | |
49 | 51 | | |
| 52 | + | |
50 | 53 | | |
51 | 54 | | |
52 | 55 | | |
| |||
130 | 133 | | |
131 | 134 | | |
132 | 135 | | |
133 | | - | |
| 136 | + | |
134 | 137 | | |
135 | 138 | | |
| 139 | + | |
136 | 140 | | |
137 | 141 | | |
138 | | - | |
139 | | - | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
140 | 145 | | |
141 | 146 | | |
142 | 147 | | |
| |||
158 | 163 | | |
159 | 164 | | |
160 | 165 | | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
161 | 180 | | |
162 | 181 | | |
163 | 182 | | |
| |||
178 | 197 | | |
179 | 198 | | |
180 | 199 | | |
| 200 | + | |
181 | 201 | | |
182 | 202 | | |
183 | 203 | | |
| |||
212 | 232 | | |
213 | 233 | | |
214 | 234 | | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
215 | 273 | | |
216 | 274 | | |
| 275 | + | |
217 | 276 | | |
218 | 277 | | |
219 | | - | |
| 278 | + | |
220 | 279 | | |
221 | 280 | | |
222 | 281 | | |
| |||
0 commit comments