Skip to content

Commit

Permalink
lint errors fixed, compiling works, 415/418 tests pass (TODO)
Browse files Browse the repository at this point in the history
  • Loading branch information
robrez committed Jan 7, 2022
1 parent 22bb93f commit 1442e3e
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 27 deletions.
20 changes: 10 additions & 10 deletions core/emitter.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import EventEmitter from 'eventemitter3';
import instances from './instances';
// import instances from './instances';
import logger from './logger';

const debug = logger('quill:events');
const EVENTS = ['selectionchange', 'mousedown', 'mouseup', 'click'];
const EMITTERS = [];
const supportsRootNode = ('getRootNode' in document);
const supportsRootNode = 'getRootNode' in document;

EVENTS.forEach(eventName => {
document.addEventListener(eventName, (...args) => {
EMITTERS.forEach((em) => {
EMITTERS.forEach(em => {
em.handleDOM(...args);
});
});
Expand All @@ -29,18 +29,18 @@ class Emitter extends EventEmitter {
}

handleDOM(event, ...args) {
const target = (event.composedPath ? event.composedPath()[0] : event.target);
const containsNode = (node, target) => {
if (!supportsRootNode || target.getRootNode() === document) {
return node.contains(target);
const target = event.composedPath ? event.composedPath()[0] : event.target;
const containsNode = (node, targetNode) => {
if (!supportsRootNode || targetNode.getRootNode() === document) {
return node.contains(targetNode);
}

while (!node.contains(target)) {
const root = target.getRootNode();
while (!node.contains(targetNode)) {
const root = targetNode.getRootNode();
if (!root || !root.host) {
return false;
}
target = root.host;
targetNode = root.host;
}

return true;
Expand Down
19 changes: 12 additions & 7 deletions core/selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ class Selection {
this.composing = false;
this.mouseDown = false;
this.root = this.scroll.domNode;
this.rootDocument = (this.root.getRootNode ? this.root.getRootNode() : document);
this.rootDocument = this.root.getRootNode
? this.root.getRootNode()
: document;
this.cursor = this.scroll.create('cursor', this);
// savedRange is last non-null range
this.savedRange = new Range(0, 0);
Expand All @@ -42,11 +44,14 @@ class Selection {
// We might need to hack the offset on Safari, when we are dealing with the first character of a row.
// This likely happens because of a race condition between quill's update method being called before the
// selectionchange event being fired in the selection polyfill.
const hackOffset = (native.start.offset === 0 &&
native.start.offset === native.end.offset &&
this.rootDocument.getSelection() instanceof ShadowSelection &&
mutations.some((a) => a.type === 'characterData' && a.oldValue === '')) ? 1 : 0;
if (native.start.node === this.cursor.textNode) return; // cursor.restore() will handle
const hackOffset =
native.start.offset === 0 &&
native.start.offset === native.end.offset &&
this.rootDocument.getSelection() instanceof ShadowSelection &&
mutations.some(a => a.type === 'characterData' && a.oldValue === '')
? 1
: 0;
if (native.start.node === this.cursor.textNode) return; // cursor.restore() will handle
// TODO unclear if this has negative side effects
this.emitter.once(Emitter.events.SCROLL_UPDATE, () => {
try {
Expand All @@ -58,7 +63,7 @@ class Selection {
native.start.node,
native.start.offset + hackOffset,
native.end.node,
native.end.offset + hackOffset
native.end.offset + hackOffset,
);
}
this.update(Emitter.sources.SILENT);
Expand Down
3 changes: 2 additions & 1 deletion modules/clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ class Clipboard extends Module {
if (!html && files.length > 0) {
this.quill.uploader.upload(range, files);
return;
} else if (html && files.length > 0) {
}
if (html && files.length > 0) {
const doc = new DOMParser().parseFromString(html, 'text/html');
if (
doc.body.childElementCount === 1 &&
Expand Down
6 changes: 4 additions & 2 deletions modules/toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Quill from '../core/quill';
import logger from '../core/logger';
import Module from '../core/module';

const supportsRootNode = ('getRootNode' in document);
const supportsRootNode = 'getRootNode' in document;
const debug = logger('quill:toolbar');

class Toolbar extends Module {
Expand All @@ -16,7 +16,9 @@ class Toolbar extends Module {
quill.container.parentNode.insertBefore(container, quill.container);
this.container = container;
} else if (typeof this.options.container === 'string') {
const rootDocument = (supportsRootNode ? quill.container.getRootNode() : document);
const rootDocument = supportsRootNode
? quill.container.getRootNode()
: document;
this.container = rootDocument.querySelector(this.options.container);
} else {
this.container = this.options.container;
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
}
},
"eslintIgnore": [
"core/shadow-selection-polyfill.js",
"dist/",
"docs/",
"node_modules/"
Expand Down
10 changes: 5 additions & 5 deletions test/unit/core/selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,18 @@ describe('Selection', function() {
});

it('getRange()', function() {
let selection = this.initialize(Selection, '<p>0123</p>', container);
const selection = this.initialize(Selection, '<p>0123</p>', container);
selection.setNativeRange(container.firstChild.firstChild, 1);
let [range, ] = selection.getRange();
const [range] = selection.getRange();
expect(range.index).toEqual(1);
expect(range.length).toEqual(0);
});

it('setRange()', function() {
let selection = this.initialize(Selection, '', container);
let expected = new Range(0);
const selection = this.initialize(Selection, '', container);
const expected = new Range(0);
selection.setRange(expected);
let [range, ] = selection.getRange();
const [range] = selection.getRange();
expect(range).toEqual(expected);
expect(selection.hasFocus()).toBe(true);
});
Expand Down
4 changes: 2 additions & 2 deletions test/unit/modules/toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ describe('Toolbar', function() {

editor = new Quill(container.shadowRoot.querySelector('.editor'), {
modules: {
toolbar: '.toolbar'
}
toolbar: '.toolbar',
},
});
});

Expand Down

0 comments on commit 1442e3e

Please sign in to comment.