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

[pull] develop from quilljs:develop #30

Merged
merged 2 commits into from
Nov 22, 2023
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
4 changes: 1 addition & 3 deletions core/editor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import cloneDeep from 'lodash.clonedeep';
import isEqual from 'lodash.isequal';
import merge from 'lodash.merge';
import { cloneDeep, isEqual, merge } from 'lodash-es';
import { LeafBlot, EmbedBlot, Scope, ParentBlot } from 'parchment';
import type { Blot } from 'parchment';
import Delta, { AttributeMap, Op } from 'quill-delta';
Expand Down
3 changes: 1 addition & 2 deletions core/quill.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import cloneDeep from 'lodash.clonedeep';
import merge from 'lodash.merge';
import { cloneDeep, merge } from 'lodash-es';
import * as Parchment from 'parchment';
import type { Op } from 'quill-delta';
import Delta from 'quill-delta';
Expand Down
3 changes: 1 addition & 2 deletions core/selection.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { LeafBlot, Scope } from 'parchment';
import cloneDeep from 'lodash.clonedeep';
import isEqual from 'lodash.isequal';
import { cloneDeep, isEqual } from 'lodash-es';
import Emitter from './emitter';
import type { EmitterSource } from './emitter';
import logger from './logger';
Expand Down
3 changes: 1 addition & 2 deletions modules/keyboard.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import cloneDeep from 'lodash.clonedeep';
import isEqual from 'lodash.isequal';
import { cloneDeep, isEqual } from 'lodash-es';
import Delta, { AttributeMap } from 'quill-delta';
import { EmbedBlot, Scope, TextBlot } from 'parchment';
import type { Blot, BlockBlot } from 'parchment';
Expand Down
7 changes: 5 additions & 2 deletions modules/uiNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import Quill from '../core/quill';

const isMac = /Mac/i.test(navigator.platform);

// Export for testing
export const TTL_FOR_VALID_SELECTION_CHANGE = 100;

// A loose check to determine if the shortcut can move the caret before a UI node:
// <ANY_PARENT>[CARET]<div class="ql-ui"></div>[CONTENT]</ANY_PARENT>
const canMoveCaretBeforeUINode = (event: KeyboardEvent) => {
Expand Down Expand Up @@ -78,10 +81,10 @@ class UINode extends Module {
* the selection within the handler of a `selectionchange` event.
*/
private ensureListeningToSelectionChange() {
if (this.isListening) return;
this.selectionChangeDeadline = Date.now() + TTL_FOR_VALID_SELECTION_CHANGE;

if (this.isListening) return;
this.isListening = true;
this.selectionChangeDeadline = Date.now() + 100;

const listener = () => {
this.isListening = false;
Expand Down
72 changes: 22 additions & 50 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
],
"dependencies": {
"eventemitter3": "^4.0.7",
"lodash.clonedeep": "^4.5.0",
"lodash.isequal": "^4.5.0",
"lodash.merge": "^4.5.0",
"parchment": "^3.0.0-alpha.1",
"quill-delta": "^5.1.0"
},
Expand All @@ -28,9 +25,7 @@
"@babel/preset-env": "^7.22.5",
"@babel/preset-typescript": "^7.22.5",
"@playwright/test": "^1.39.0",
"@types/lodash.clonedeep": "^4.5.7",
"@types/lodash.isequal": "^4.5.6",
"@types/lodash.merge": "^4.6.7",
"@types/lodash-es": "^4.17.11",
"@typescript-eslint/eslint-plugin": "^6.9.1",
"@typescript-eslint/parser": "^6.9.1",
"@vitest/browser": "^0.34.6",
Expand All @@ -48,6 +43,7 @@
"http-proxy": "^1.18.0",
"jsdom": "^22.1.0",
"lodash": "^4.17.15",
"lodash-es": "^4.17.21",
"mini-css-extract-plugin": "^2.7.6",
"npm-run-all": "^4.1.5",
"prettier": "^3.0.3",
Expand Down
41 changes: 41 additions & 0 deletions test/unit/modules/uiNode.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import '../../../quill';
import { describe, expect, test } from 'vitest';
import UINode, {
TTL_FOR_VALID_SELECTION_CHANGE,
} from '../../../modules/uiNode';
import Quill, { Delta } from '../../../core';

// Fake timer is not supported in browser mode yet.
const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));

describe('uiNode', () => {
test('extends deadline when multiple possible shortcuts are pressed', async () => {
const quill = new Quill(document.createElement('div'));
document.body.appendChild(quill.container);
quill.setContents(
new Delta().insert('item 1').insert('\n', { list: 'bullet' }),
);
new UINode(quill, {});

for (let i = 0; i < 2; i += 1) {
quill.root.dispatchEvent(
new KeyboardEvent('keydown', { key: 'ArrowRight', metaKey: true }),
);
await delay(TTL_FOR_VALID_SELECTION_CHANGE / 2);
}

quill.root.dispatchEvent(
new KeyboardEvent('keydown', { key: 'ArrowLeft', metaKey: true }),
);
const range = document.createRange();
range.setStart(quill.root.querySelector('li')!, 0);
range.setEnd(quill.root.querySelector('li')!, 0);

const selection = document.getSelection();
selection?.removeAllRanges();
selection?.addRange(range);

await delay(TTL_FOR_VALID_SELECTION_CHANGE / 2);
expect(selection?.getRangeAt(0).startOffset).toEqual(1);
});
});
2 changes: 1 addition & 1 deletion themes/base.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import merge from 'lodash.merge';
import { merge } from 'lodash-es';
import type Quill from '../core/quill';
import Emitter from '../core/emitter';
import Theme from '../core/theme';
Expand Down
2 changes: 1 addition & 1 deletion themes/bubble.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import merge from 'lodash.merge';
import { merge } from 'lodash-es';
import Emitter from '../core/emitter';
import BaseTheme, { BaseTooltip } from './base';
import { Range } from '../core/selection';
Expand Down
2 changes: 1 addition & 1 deletion themes/snow.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import merge from 'lodash.merge';
import { merge } from 'lodash-es';
import Emitter from '../core/emitter';
import BaseTheme, { BaseTooltip } from './base';
import LinkBlot from '../formats/link';
Expand Down