From 6e5710364e1cc447377a10c6860d1994150589ce Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Wed, 14 Mar 2018 16:13:33 +0000 Subject: [PATCH] Koenig - Fixed backspace not deleting empty para at beginning of doc refs https://github.com/TryGhost/Ghost/issues/9311 - something that became apparent after adding the "Enter in post title adds blank paragraph" feature was that using that feature left you in a position where Backspace doesn't do what you expect - it does nothing rather than deleting the blank paragraph - added logic to the `handleBackspaceKey` handler in `{{koenig-editor}}` to detect when backspace is pressed on a blank paragraph at the start of the doc so that we remove it then focus the title --- .../addon/components/koenig-editor.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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 531aef5fdf..bb4df190b1 100644 --- a/ghost/admin/lib/koenig-editor/addon/components/koenig-editor.js +++ b/ghost/admin/lib/koenig-editor/addon/components/koenig-editor.js @@ -528,6 +528,20 @@ export default Component.extend({ return; } + // if the caret is at the beginning of the doc, on a blank para, and + // there are more sections then delete the para and trigger the + // `cursorDidExitAtTop` closure action + let isFirstSection = section === section.parent.sections.head; + if (isFirstSection && isCollapsed && offset === 0 && (section.isBlank || section.text === '') && section.next) { + this.editor.run((postEditor) => { + postEditor.removeSection(section); + }); + + // allow default behaviour which will trigger `cursorDidChange` and + // fire our `cursorDidExitAtTop` action + return; + } + // if the section about to be deleted by a backspace is a card then // actually delete the card rather than selecting it. // However, if the current paragraph is blank then delete the paragraph