From d0c059d0a7f9961f181226e88c7cd35362616665 Mon Sep 17 00:00:00 2001 From: "polosatov.alexander" Date: Wed, 19 Apr 2023 17:19:28 +0400 Subject: [PATCH] Should be no errors when list pasting into table(T1155500) (#90) --- core/selection.js | 13 +++-- test/functional/epic.js | 39 +++++++++++++- .../example/table_copy_pasting.html | 51 +++++++++++++++++++ 3 files changed, 98 insertions(+), 5 deletions(-) create mode 100644 test/functional/example/table_copy_pasting.html diff --git a/core/selection.js b/core/selection.js index ef4f3a15fc..0913a16bc4 100644 --- a/core/selection.js +++ b/core/selection.js @@ -140,13 +140,13 @@ class Selection { let node; let [leaf, offset] = this.scroll.leaf(index); if (leaf == null) return null; - [node, offset] = leaf.position(offset, true); + [node, offset] = this.getPositionData(leaf, offset, true); const range = document.createRange(); if (length > 0) { range.setStart(node, offset); [leaf, offset] = this.scroll.leaf(index + length); if (leaf == null) return null; - [node, offset] = leaf.position(offset, true); + [node, offset] = this.getPositionData(leaf, offset, true); range.setEnd(node, offset); return range.getBoundingClientRect(); } @@ -277,7 +277,7 @@ class Selection { indexes.forEach((index, i) => { index = Math.min(scrollLength - 1, index); const [leaf, leafOffset] = this.scroll.leaf(index); - const [node, offset] = leaf.position(leafOffset, i !== 0); + const [node, offset] = this.getPositionData(leaf, leafOffset, i !== 0); args.push(node, offset); }); if (args.length < 2) { @@ -286,6 +286,13 @@ class Selection { return args; } + getPositionData(leaf, offset, inclusive) { + if (leaf instanceof LeafBlot) { + return leaf.position(offset, inclusive); + } + return [leaf.domNode, offset]; + } + scrollIntoView(scrollingContainer) { const range = this.lastRange; if (range == null) return; diff --git a/test/functional/epic.js b/test/functional/epic.js index 28140ab073..c06e5e5b0c 100644 --- a/test/functional/epic.js +++ b/test/functional/epic.js @@ -3,13 +3,15 @@ const puppeteer = require('puppeteer'); jasmine.DEFAULT_TIMEOUT_INTERVAL = 100000; -const SHORTKEY = process.platform === 'darwin' ? 'Meta' : 'Control'; +const isMac = process.platform === 'darwin'; +const SHORTKEY = isMac ? 'Meta' : 'Control'; const CHAPTER = 'Chapter 1. Loomings.'; const GUARD_CHAR = '\uFEFF'; const EMBED = `${GUARD_CHAR}#test${GUARD_CHAR}`; const P1 = 'Call me Ishmael. Some years ago—never mind how long precisely-having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world. It is a way I have of driving off the spleen and regulating the circulation. Whenever I find myself growing grim about the mouth; whenever it is a damp, drizzly November in my soul; whenever I find myself involuntarily pausing before coffin warehouses, and bringing up the rear of every funeral I meet; and especially whenever my hypos get such an upper hand of me, that it requires a strong moral principle to prevent me from deliberately stepping into the street, and methodically knocking people’s hats off—then, I account it high time to get to sea as soon as I can. This is my substitute for pistol and ball. With a philosophical flourish Cato throws himself upon his sword; I quietly take to the ship. There is nothing surprising in this. If they but knew it, almost all men in their degree, some time or other, cherish very nearly the same feelings towards the ocean with me.'; const P2 = 'There now is your insular city of the Manhattoes, belted round by wharves as Indian isles by coral reefs—commerce surrounds it with her surf. Right and left, the streets take you waterward. Its extreme downtown is the battery, where that noble mole is washed by waves, and cooled by breezes, which a few hours previous were out of sight of land. Look at the crowds of water-gazers there.'; +const HOST = 'http://127.0.0.1:8080'; describe('quill', function () { it('compose an epic', async function () { @@ -18,7 +20,7 @@ describe('quill', function () { }); const page = await browser.newPage(); - await page.goto('http://127.0.0.1:8080/index.html'); + await page.goto(`${HOST}/index.html`); await page.waitForSelector('.ql-editor', { timeout: 10000 }); const title = await page.title(); expect(title).toEqual('DevExtreme-Quill Base Editing'); @@ -247,6 +249,39 @@ describe('quill', function () { }); }); +// Copy/paste emulation des not working on Mac. See https://github.com/puppeteer/puppeteer/issues/1313 +if (!isMac) { + describe('List copy/pasting into table', function () { + it('Should be no errors when list is pasted into table cell(T1155500)', async function () { + const tableCellSelector = '[data-table-cell="2"]'; + const browser = await puppeteer.launch({ + headless: false, + }); + const page = await browser.newPage(); + const pressKeyWithShortkey = async (keyName) => { + await page.keyboard.down(SHORTKEY); + await page.keyboard.press(keyName); + await page.keyboard.up(SHORTKEY); + }; + + await page.goto(`${HOST}/table_copy_pasting.html`); + await page.waitForSelector('.ql-editor', { timeout: 10000 }); + + page.on('pageerror', () => { + expect(true).toEqual(false); + }); + + pressKeyWithShortkey('c'); + await page.click(tableCellSelector); + pressKeyWithShortkey('v'); + + const liElementsCount = await page.$$eval('li', (e) => e.length); + + expect(liElementsCount).toEqual(4); + }); + }); +} + function getSelectionInTextNode() { const { anchorNode, anchorOffset, focusNode, focusOffset, diff --git a/test/functional/example/table_copy_pasting.html b/test/functional/example/table_copy_pasting.html new file mode 100644 index 0000000000..237e164cb5 --- /dev/null +++ b/test/functional/example/table_copy_pasting.html @@ -0,0 +1,51 @@ + + + + + + + + DevExtreme-Quill + + + + + +
+
+ + + + + + + + +
+
    +
  1. hello
  2. +
  3. hello
  4. +
+
+

t

+
+

text

+
+
+
+
+ + + + +