mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-24 23:48:13 -05:00
🐛 Koenig - Fixed error when dropping an image before the editor has focus
refs https://github.com/TryGhost/Ghost/issues/9724 - adjust `insertImageCards()` to handle the editor not having an active section - add `jumpToCard` option to `_scrollCursorIntoView()` so that we can scroll to a card when appropriate - call `_scrollCursorIntoView()` after dropping images and creating cards
This commit is contained in:
parent
159cc5f010
commit
f4a21bd1f6
1 changed files with 19 additions and 2 deletions
|
@ -118,6 +118,22 @@ function insertImageCards(files, postEditor) {
|
||||||
let collection = editor.post.sections;
|
let collection = editor.post.sections;
|
||||||
let section = editor.activeSection;
|
let section = editor.activeSection;
|
||||||
|
|
||||||
|
// when dropping an image on the editor before it's had focus there will be
|
||||||
|
// no active section so we insert the image at the end of the document
|
||||||
|
if (!section) {
|
||||||
|
section = editor.post.sections.tail;
|
||||||
|
|
||||||
|
// create a blank paragraph at the end of the document if needed because
|
||||||
|
// we use `insertSectionBefore` and don't want the image to be added
|
||||||
|
// before the last card
|
||||||
|
if (!section.isMarkerable) {
|
||||||
|
let blank = builder.createMarkupSection();
|
||||||
|
postEditor.insertSectionAtEnd(blank);
|
||||||
|
postEditor.setRange(blank.toRange());
|
||||||
|
section = postEditor._range.head.section;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// place the card after the active section
|
// place the card after the active section
|
||||||
if (!section.isBlank && !section.isListItem && section.next) {
|
if (!section.isBlank && !section.isListItem && section.next) {
|
||||||
section = section.next;
|
section = section.next;
|
||||||
|
@ -899,6 +915,7 @@ export default Component.extend({
|
||||||
this.editor.run((postEditor) => {
|
this.editor.run((postEditor) => {
|
||||||
insertImageCards(images, postEditor);
|
insertImageCards(images, postEditor);
|
||||||
});
|
});
|
||||||
|
this._scrollCursorIntoView({jumpToCard: true});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -1064,7 +1081,7 @@ export default Component.extend({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
_scrollCursorIntoView() {
|
_scrollCursorIntoView(options = {jumpToCard: false}) {
|
||||||
// disable auto-scroll if the mouse or shift key is being used to create
|
// disable auto-scroll if the mouse or shift key is being used to create
|
||||||
// a selection - the browser handles scrolling well in this case
|
// a selection - the browser handles scrolling well in this case
|
||||||
if (!this._scrollContainer || this._isMouseDown || this._modifierKeys.shift) {
|
if (!this._scrollContainer || this._isMouseDown || this._modifierKeys.shift) {
|
||||||
|
@ -1081,7 +1098,7 @@ export default Component.extend({
|
||||||
let element = range.head && range.head.section && range.head.section.renderNode && range.head.section.renderNode.element;
|
let element = range.head && range.head.section && range.head.section.renderNode && range.head.section.renderNode.element;
|
||||||
|
|
||||||
// prevent scroll jumps when a card is selected
|
// prevent scroll jumps when a card is selected
|
||||||
if (range && range.head.section && range.head.section.isCardSection) {
|
if (!options.jumpToCard && range && range.head.section && range.head.section.isCardSection) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue