Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
🐛 Koenig - Fixed pasting content into a container card (HTML, markdow…
Browse files Browse the repository at this point in the history
…n, code)

refs TryGhost/Ghost#9623
- pasting inside a container card such as markdown or HTML would paste content into the card and duplicate that content outside of the card, exiting the card's edit mode in the process
- use the same "addressable" check that mobiledoc-kit's event manager uses
  • Loading branch information
kevinansfield committed May 28, 2018
1 parent 29e7624 commit bc309a0
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/koenig-editor/addon/components/koenig-editor.js
Expand Up @@ -637,11 +637,20 @@ export default Component.extend({

handlePaste(event) {
let editor = this.editor;
let {target: element} = event;

// don't trigger our paste handling for pastes within cards or outside
// of the editor canvas. Avoids double-paste of content when pasting
// into cards
if (!editor.cursor.isAddressable(element)) {
return;
}

let range = editor.range;
let {html, text} = getContentFromPasteEvent(event);

// if a URL is pasted and we have a selection, make that selection a link
if (range && !range.isCollapsed && range.headSection === range.tailSection && range.headSection.isMarkerable) {
let {text} = getContentFromPasteEvent(event);
if (text && validator.isURL(text)) {
let linkMarkup = editor.builder.createMarkup('a', {href: text});
editor.run((postEditor) => {
Expand All @@ -659,7 +668,6 @@ export default Component.extend({
// we get better output than mobiledoc's default text parsing and we can
// provide an easier MD->Mobiledoc conversion route
// NOTE: will not work in IE/Edge which only ever expose `html`
let {html, text} = getContentFromPasteEvent(event);
if (text && !html && !this._modifierKeys.shift) {
// prevent mobiledoc's default paste event handler firing
event.preventDefault();
Expand Down

0 comments on commit bc309a0

Please sign in to comment.