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

Commit

Permalink
Koenig - Fix error when inserting cards in certain circumstances
Browse files Browse the repository at this point in the history
refs TryGhost/Ghost#9311
- the card selection in `cursorDidChange` would sometimes fail because the selection would be attempted before the newly inserted card had been pushed on to the `componentCards` array. This was reliably triggered by adding a card to a blank header section via the /-menu
- scheduling the section `afterRender` ensures that the `willRender` hook has fired and populated the `componentCards` array before the selection occurs
  • Loading branch information
kevinansfield committed Mar 14, 2018
1 parent 55a99cb commit 2dd4305
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/koenig-editor/addon/components/koenig-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,9 +470,13 @@ export default Component.extend({
// select the card if the cursor is on the before/after ‌ char
if (section && isCollapsed && section.type === 'card-section') {
if (head.offset === 0 || head.offset === 1) {
let card = this._getCardFromSection(section);
this.selectCard(card);
this.set('selectedRange', editor.range);
// select card after render to ensure that our componentCards
// attr is populated
run.schedule('afterRender', this, () => {
let card = this._getCardFromSection(section);
this.selectCard(card);
this.set('selectedRange', editor.range);
});
return;
}
}
Expand Down

0 comments on commit 2dd4305

Please sign in to comment.