Commit ce737e3
fix(caret): misalignment issue when switching between carets (@byseif21) (monkeytypegame#6642)
### Description
fixes a caret misalignment issue that occurred when switching between
caret styles (e.g., from block/outline/underline to line caret).
#### Bug:
When switching caret styles, the **line caret** could retain the width
from the previous style (e.g., block), causing it to appear **visually
incorrect** until the next input.
#### Root Cause:
* The caret's inline `width` was **not reset** when changing styles, so
the new style inherited the old dimensions.
* `updatePosition()` was called **before** the style was fully applied,
leading to **incorrect positioning**.
---
### Fix
* Added a `subscribe` listener in `caret.ts` for the `"caretStyle"`
event.
* When the caret style changes:
* The caret's inline width is **reset**:
```ts
caret.style.width = "";
```
* Its position is immediately **recalculated** with:
```ts
updatePosition(true);
```
---------
Co-authored-by: Miodec <[email protected]>1 parent de447c2 commit ce737e3
1 file changed
+38
-16
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
132 | 133 | | |
133 | 134 | | |
134 | 135 | | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
135 | 157 | | |
136 | 158 | | |
137 | 159 | | |
| |||
176 | 198 | | |
177 | 199 | | |
178 | 200 | | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
191 | 208 | | |
192 | 209 | | |
193 | 210 | | |
| |||
209 | 226 | | |
210 | 227 | | |
211 | 228 | | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
| 229 | + | |
| 230 | + | |
216 | 231 | | |
217 | 232 | | |
218 | 233 | | |
| |||
250 | 265 | | |
251 | 266 | | |
252 | 267 | | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
253 | 275 | | |
254 | 276 | | |
255 | 277 | | |
| |||
0 commit comments