Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Placeholder): fixed issue with displaying a fake cursor in Safari #212

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading