Skip to content

Commit

Permalink
fix(Placeholder): fixed issue with displaying a fake cursor in Safari (
Browse files Browse the repository at this point in the history
  • Loading branch information
d3m1d0v authored Apr 4, 2024
1 parent 978a828 commit c9c6fb5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
27 changes: 10 additions & 17 deletions src/extensions/behavior/Placeholder/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
}

@keyframes placeholder_blink {
1% {
border-color: unset;
}
49% {
border-color: unset;
}
Expand All @@ -28,22 +25,18 @@
.ye-placeholder {
caret-color: transparent;

&::before {
position: relative;
z-index: 1;

display: inline-block;
.ProseMirror-focused &_focus {
.ye-placeholder__cursor {
position: relative;
z-index: 1;

margin-right: -1px;
margin-right: -1px;

content: '';
caret-color: transparent;

border-right: 1px solid transparent;
}
border-left-width: 1px;
border-left-style: solid;

.ProseMirror-focused &_focus::before {
animation: placeholder_blink 1s;
animation-iteration-count: infinite;
animation: placeholder_blink 1s;
animation-iteration-count: infinite;
}
}
}
13 changes: 11 additions & 2 deletions src/extensions/behavior/Placeholder/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,17 @@ export const createPlaceholder = (node: Node, parent: Node | null, focus?: boole
if (!content) return null;

const placeholder = document.createElement('div');
placeholder.classList.add(...b({focus}).split(' '));
placeholder.textContent = content;
placeholder.className = b({focus});

const placeholderCursor = document.createElement('span');
placeholderCursor.className = b('cursor');

const placeholderText = document.createElement('span');
placeholderText.className = b('text');
placeholderText.textContent = content;

placeholder.append(placeholderCursor, placeholderText);

return placeholder;
};

Expand Down

0 comments on commit c9c6fb5

Please sign in to comment.