Skip to content

Commit

Permalink
Should be no errors when list pasting into table(T1155500) (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderPolosatov authored Apr 19, 2023
1 parent 4571f02 commit d0c059d
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 5 deletions.
13 changes: 10 additions & 3 deletions core/selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand Down
39 changes: 37 additions & 2 deletions test/functional/epic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `<span>${GUARD_CHAR}<span contenteditable="false"><span contenteditable="false">#test</span></span>${GUARD_CHAR}</span>`;
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 () {
Expand All @@ -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');
Expand Down Expand Up @@ -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,
Expand Down
51 changes: 51 additions & 0 deletions test/functional/example/table_copy_pasting.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DevExtreme-Quill</title>
<link rel="stylesheet" type="text/css" href="src/dx-quill.core.css" />
<script type="text/javascript" src="src/dx-quill.js"></script>
</head>

<body>
<div>
<div id="editor">
<table>
<tbody>
<tr>
<td>
<ol>
<li>hello</li>
<li>hello</li>
</ol>
</td>
<td>
<p>t</p>
</td>
<td>
<p>text</p>
</td>
</tr>
</tbody>
</table>
<br>
</div>
</div>
</body>

<script>
const editorContainer = document.getElementById('editor');
const quillInstance = new DevExpress.Quill(editorContainer, {
modules: {
table: true
}
});

quillInstance.focus();
quillInstance.setSelection(2, 6);
</script>

</html>

0 comments on commit d0c059d

Please sign in to comment.