Skip to content
Snippets Groups Projects
Commit 87091b6f authored by chris's avatar chris
Browse files

fix fake cursor multiple dropdowns

parent 38a4d4b6
No related branches found
No related tags found
1 merge request!519Move tool groups
...@@ -12,11 +12,13 @@ export default props => { ...@@ -12,11 +12,13 @@ export default props => {
init: (_, state) => {}, init: (_, state) => {},
apply(tr, prev, _, newState) { apply(tr, prev, _, newState) {
let createDecoration; let createDecoration;
if ( if (
newState.selection.from === newState.selection.to && newState.selection.from === newState.selection.to &&
Commands.isInTable(newState) Commands.isInTable(newState)
) { ) {
const widget = document.createElement('fakecursor'); const widget = document.createElement('span');
widget.setAttribute('id', 'fake-cursor');
createDecoration = DecorationSet.create(newState.doc, [ createDecoration = DecorationSet.create(newState.doc, [
Decoration.widget(newState.selection.from, widget, { Decoration.widget(newState.selection.from, widget, {
key: 'fakecursor', key: 'fakecursor',
...@@ -38,22 +40,34 @@ export default props => { ...@@ -38,22 +40,34 @@ export default props => {
handleDOMEvents: { handleDOMEvents: {
focus: (view, event) => { focus: (view, event) => {
event.preventDefault(); event.preventDefault();
const fakeCursor = document.getElementsByTagName('fakecursor'); const fakeCursor = document.getElementById('fake-cursor');
if (fakeCursor && fakeCursor[0]) { if (fakeCursor) {
for (let i = 0; i < fakeCursor.length; i++) { if (
fakeCursor[i].style.visibility = 'hidden'; navigator.userAgent.includes('Firefox') &&
view.state.selection.$from.nodeBefore == null
) {
fakeCursor.style.visibility = 'hidden';
} else {
fakeCursor.style.display = 'none';
} }
} }
}, },
blur: (view, event) => { blur: (view, event) => {
event.preventDefault(); event.preventDefault();
if (view && event.relatedTarget === null) { if (view && event.relatedTarget === null) {
view.focus(); setTimeout(() => {
view.focus();
});
} else { } else {
const fakeCursor = document.getElementsByTagName('fakecursor'); const fakeCursor = document.getElementById('fake-cursor');
if (fakeCursor && fakeCursor[0]) { if (fakeCursor) {
for (let i = 0; i < fakeCursor.length; i++) { if (
fakeCursor[i].style.visibility = 'visible'; navigator.userAgent.includes('Firefox') &&
view.state.selection.$from.nodeBefore === null
) {
fakeCursor.style.visibility = 'visible';
} else {
fakeCursor.style.display = 'inline';
} }
} }
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment