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

Commit

Permalink
Koenig - Remove trailing paragraph on paste workaround
Browse files Browse the repository at this point in the history
refs TryGhost/Ghost#9623
- now that we're not creating unnecessary undo states, pasting cards with an immediate Cmd+Z works fine so we don't need to create a trailing paragraph as a partial workaround
  • Loading branch information
kevinansfield committed May 23, 2018
1 parent f232d3b commit c81b39e
Showing 1 changed file with 0 additions and 30 deletions.
30 changes: 0 additions & 30 deletions lib/koenig-editor/addon/components/koenig-editor.js
Expand Up @@ -523,8 +523,6 @@ export default Component.extend({

cursorDidChange(editor) {
let {head, tail, direction, isCollapsed, head: {section}} = editor.range;
let isPasting = this._isPasting;
this._isPasting = false;

// sometimes we perform a programatic edit that causes a cursor change
// but we actually want to skip the default behaviour because we've
Expand All @@ -545,29 +543,6 @@ export default Component.extend({

// select the card if the cursor is on the before/after ‌ char
if (section && isCollapsed && section.type === 'card-section') {
if (isPasting) {
// when pasting, if the last section added is a card we don't want to
// select it (it breaks the undo stack) but rather create an empty
// paragraph underneath
// TODO: why does the undo stack break?
let collection = section.parent.sections;
let nextSection = section.next;
editor.run((postEditor) => {
let newSection = postEditor.builder.createMarkupSection('p');

if (nextSection) {
postEditor.insertSectionBefore(collection, newSection, nextSection);
} else {
postEditor.insertSectionAtEnd(newSection);
}

postEditor.setRange(newSection.tailPosition());
this.set('selectedRange', newSection.tailPosition());
this._skipCursorChange = true;
});
return;
}

if (head.offset === 0 || head.offset === 1) {
// select card after render to ensure that our componentCards
// attr is populated
Expand Down Expand Up @@ -642,11 +617,6 @@ export default Component.extend({
let editor = this.editor;
let range = editor.range;

// when pasting, if the last section added is a card we don't want to
// select it (it breaks the undo stack) but rather create an empty
// paragraph underneath
this._isPasting = true;

// 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);
Expand Down

0 comments on commit c81b39e

Please sign in to comment.