From 26dd4ffb4a63236c285102ddfa9eb7e0436e0680 Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Thu, 15 Feb 2018 15:52:08 +0000 Subject: [PATCH] Koenig - Fix cards being deselected when clicking in edit mode refs https://github.com/TryGhost/Ghost/issues/9311 - there was an issue where clicking inside a card whilst it was in edit mode would cause the cursor position in the editor to change from the end of a card to the beginning which would re-run our card selection routine and de-selecting the card - add a guard to the `cursorDidChange` method that looks for an end-to-beginning move whilst a card is in edit mode and ignores it --- .../koenig-editor/addon/components/koenig-editor.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ghost/admin/lib/koenig-editor/addon/components/koenig-editor.js b/ghost/admin/lib/koenig-editor/addon/components/koenig-editor.js index b7e161cfba..0d953d9484 100644 --- a/ghost/admin/lib/koenig-editor/addon/components/koenig-editor.js +++ b/ghost/admin/lib/koenig-editor/addon/components/koenig-editor.js @@ -406,6 +406,9 @@ export default Component.extend({ }, cursorDidChange(editor) { + let {head, isCollapsed, head: {section}} = editor.range; + let selectedRange = this.get('selectedRange'); + // sometimes we perform a programatic edit that causes a cursor change // but we actually want to skip the default behaviour because we've // already handled it, e.g. on card insertion, manual card selection @@ -415,7 +418,14 @@ export default Component.extend({ return; } - let {head, isCollapsed, head: {section}} = editor.range; + // skip everything if the cursor is just moving from the end of a card + // section to the beginning whilst a card is in edit mode, this prevents + // clicks within a card causing the card to be deselected. Only applies + // when a card is in edit mode otherwise it's necessary to press LEFT + // twice to cycle up through cards + if (this._selectedCard && this._selectedCard.isEditing && selectedRange && isCollapsed && editor.range.headSection === selectedRange.headSection && editor.range.head.offset === 0 && selectedRange.head.offset === 1) { + return; + } // if we have a selected card but cursor has moved to the left then // deselect and move cursor to end of the previous section