Skip to content

Commit

Permalink
Improve paste function of multiple lines (#1016)
Browse files Browse the repository at this point in the history
Co-authored-by: Georgy Berezhnoy <[email protected]>
  • Loading branch information
hata6502 and gohabereg authored Mar 14, 2020
1 parent a5513a3 commit c1860c9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion dist/editor.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- `New` Block [lifecycle hook](tools.md#block-lifecycle-hooks) `moved`
- `Deprecated`[`blocks.swap(fromIndex, toIndex)`](api.md) method is deprecated. Use `blocks.move(toIndex, fromIndex)` instead.
- `Fix` — Improve plain text paste [#1012](https://github.com/codex-team/editor.js/issues/1012)
- `Fix` — Fix multiline paste [#1015](https://github.com/codex-team/editor.js/issues/1015)

### 2.16.1

Expand Down
10 changes: 5 additions & 5 deletions src/components/modules/paste.ts
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,11 @@ export default class Paste extends Module {
if (BlockManager.currentBlock && BlockManager.currentBlock.currentInput) {
const currentToolSanitizeConfig = Sanitizer.getInlineToolsConfig(BlockManager.currentBlock.name);

document.execCommand('insertHTML', false, Sanitizer.clean(content.innerHTML, currentToolSanitizeConfig));
document.execCommand(
'insertHTML',
false,
Sanitizer.clean(content.innerHTML, currentToolSanitizeConfig),
);
} else {
this.insertBlock(dataToInsert);
}
Expand Down Expand Up @@ -765,10 +769,6 @@ export default class Paste extends Module {
case Node.ELEMENT_NODE:
const element = node as HTMLElement;

if (element.tagName === 'BR') {
return [...nodes, destNode, new DocumentFragment()];
}

const {tool = ''} = this.toolsTags[element.tagName] || {};
const toolTags = this.tagsByTool[tool] || [];

Expand Down
6 changes: 6 additions & 0 deletions src/components/modules/sanitizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,12 @@ export default class Sanitizer extends Module {
});
}

/**
* Allow linebreaks
*/
config['br'] = true;
config['wbr'] = true;

return config;
}

Expand Down

0 comments on commit c1860c9

Please sign in to comment.