Skip to content

Commit fc35836

Browse files
committed
fix: align cursor in live code editor (#962)
Set explicit line-height and letter-spacing on the editor mixin so the hidden textarea and visible pre layers stay pixel-aligned. Without these, browsers compute different defaults per element type, causing the cursor to drift from the rendered text.
1 parent 1bbdfb0 commit fc35836

2 files changed

Lines changed: 4 additions & 0 deletions

File tree

components/LiveEdit.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ export const editorMixin = `
9797
font-family: ${monospace};
9898
font-size: 0.8rem;
9999
font-weight: 300;
100+
line-height: 1.5;
101+
letter-spacing: normal;
100102
min-height: ${rem(400)};
101103
overflow-x: hidden;
102104
overflow-y: auto !important;

test/components/__snapshots__/LiveEdit.spec.tsx.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ exports[`LiveEdit renders correctly 1`] = `
2121
font-family: var(--font-mono),ui-monospace,SFMono-Regular,"SF Mono",Menlo,Consolas,"Liberation Mono",monospace;
2222
font-size: 0.8rem;
2323
font-weight: 300;
24+
line-height: 1.5;
25+
letter-spacing: normal;
2426
min-height: 22.22222222222222rem;
2527
overflow-x: hidden;
2628
overflow-y: auto!important;

0 commit comments

Comments
 (0)