Skip to content

Commit c9c6fb5

Browse files
authored
fix(Placeholder): fixed issue with displaying a fake cursor in Safari (#212)
1 parent 978a828 commit c9c6fb5

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

src/extensions/behavior/Placeholder/index.scss

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
}
1212

1313
@keyframes placeholder_blink {
14-
1% {
15-
border-color: unset;
16-
}
1714
49% {
1815
border-color: unset;
1916
}
@@ -28,22 +25,18 @@
2825
.ye-placeholder {
2926
caret-color: transparent;
3027

31-
&::before {
32-
position: relative;
33-
z-index: 1;
34-
35-
display: inline-block;
28+
.ProseMirror-focused &_focus {
29+
.ye-placeholder__cursor {
30+
position: relative;
31+
z-index: 1;
3632

37-
margin-right: -1px;
33+
margin-right: -1px;
3834

39-
content: '';
40-
caret-color: transparent;
41-
42-
border-right: 1px solid transparent;
43-
}
35+
border-left-width: 1px;
36+
border-left-style: solid;
4437

45-
.ProseMirror-focused &_focus::before {
46-
animation: placeholder_blink 1s;
47-
animation-iteration-count: infinite;
38+
animation: placeholder_blink 1s;
39+
animation-iteration-count: infinite;
40+
}
4841
}
4942
}

src/extensions/behavior/Placeholder/index.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,17 @@ export const createPlaceholder = (node: Node, parent: Node | null, focus?: boole
3333
if (!content) return null;
3434

3535
const placeholder = document.createElement('div');
36-
placeholder.classList.add(...b({focus}).split(' '));
37-
placeholder.textContent = content;
36+
placeholder.className = b({focus});
37+
38+
const placeholderCursor = document.createElement('span');
39+
placeholderCursor.className = b('cursor');
40+
41+
const placeholderText = document.createElement('span');
42+
placeholderText.className = b('text');
43+
placeholderText.textContent = content;
44+
45+
placeholder.append(placeholderCursor, placeholderText);
46+
3847
return placeholder;
3948
};
4049

0 commit comments

Comments
 (0)