Skip to content

Commit

Permalink
improve table copy pasting into editor3 (#4252)
Browse files Browse the repository at this point in the history
when there is no editor instance, like from different
instance or different window.

SDNTB-814
  • Loading branch information
petrjasek authored May 25, 2023
1 parent 9d18206 commit 3dc4662
Show file tree
Hide file tree
Showing 5 changed files with 814 additions and 3 deletions.
2 changes: 1 addition & 1 deletion scripts/core/editor3/components/handlePastedText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export function handlePastedText(text: string, _html: string): DraftHandleValue
return 'handled';
}

if (htmlComesFromDraftjsEditor(html)) {
if (htmlComesFromDraftjsEditor(html, false)) {
return 'not-handled';
}

Expand Down
19 changes: 19 additions & 0 deletions scripts/core/editor3/components/tests/handlePastedText.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {cursorAtEndPosition, cursorAtPosition} from './utils';
import {insertContentInState, createHtmlFromText} from '../handlePastedText';
import {getAnnotationsFromContentState} from 'core/editor3/helpers/editor3CustomData';
import {getContentStateFromHtml} from 'core/editor3/html/from-html';
import {htmlComesFromDraftjsEditor} from 'core/editor3/helpers/htmlComesFromDraftjsEditor';
import HTML_WITH_TABLE from './pastedHtmlWithTable.html';

describe('editor3.handlePastedText', () => {
it('should insert text without selection', () => {
Expand Down Expand Up @@ -111,4 +113,21 @@ describe('editor3.handlePastedText', () => {

expect(contentState.getPlainText('\n')).toEqual(text);
});

it('should handle table blocks', () => {
const contentState = getContentStateFromHtml(HTML_WITH_TABLE);
const blocks = contentState.getBlocksAsArray();

expect(htmlComesFromDraftjsEditor(HTML_WITH_TABLE, false)).toBe(false);

expect(blocks.length).toBe(2);
expect(blocks[0].getType()).toBe("atomic");

const entity = contentState.getEntity(blocks[0].getEntityAt(0));
expect(entity.getType()).toBe("TABLE");

const tableData = entity.getData().data;
expect(tableData.numRows).toBe(6);
expect(tableData.numCols).toBe(4);
});
});
Loading

0 comments on commit 3dc4662

Please sign in to comment.