Skip to content

Commit

Permalink
Fix #234 - Cursor rendering incorrectly in firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
nmielnik committed Jun 4, 2016
1 parent d496a1c commit b004db1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/js/extensions/placeholder.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,23 @@

showPlaceholder: function (el) {
if (el) {
el.classList.add('medium-editor-placeholder');
// https://github.com/yabwe/medium-editor/issues/234
// In firefox, styling the placeholder with an absolutely positioned
// pseudo element causes the cursor to appear in a bad location
// when the element is completely empty, so apply a different class to
// style it with a relatively positioned pseudo element
if (MediumEditor.util.isFF && el.childNodes.length === 0) {
el.classList.add('medium-editor-placeholder-relative');
} else {
el.classList.add('medium-editor-placeholder');
}
}
},

hidePlaceholder: function (el) {
if (el) {
el.classList.remove('medium-editor-placeholder');
el.classList.remove('medium-editor-placeholder-relative');
}
},

Expand Down
15 changes: 14 additions & 1 deletion src/sass/components/_placeholder.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,24 @@
&:after {
content: attr(data-placeholder) !important;
font-style: italic;
left: 0;
position: absolute;
left: 0;
top: 0;
white-space: pre;
padding: inherit;
margin: inherit;
}
}

.medium-editor-placeholder-relative {
position: relative;

&:after {
content: attr(data-placeholder) !important;
font-style: italic;
position: relative;
white-space: pre;
padding: inherit;
margin: inherit;
}
}

0 comments on commit b004db1

Please sign in to comment.