Added scroll-into-view behaviour for inline image selector

refs https://github.com/TryGhost/Team/issues/1225

- added `scrollToCard` action to `koenig-editor` and passed it through to all card components curried to already include the card as an argument
  - action selects the card which places the cursor on it, then triggers our existing cursor scroll-into-view behaviour with an option to allow scrolling a card into view
- updated our cursor scroll-into-view behaviour so if the cursor is large (eg, when it covers a card's height) we make sure the top of the cursor is kept in view rather than the bottom
  - ensures that on small-height screens, opening the gif selector doesn't result in it's search bar being scrolled off screen
This commit is contained in:
Kevin Ansfield 2021-11-24 20:02:10 +00:00
parent 5116c86557
commit 0f517ad4e6
3 changed files with 19 additions and 1 deletions

View File

@ -180,6 +180,10 @@ export default Component.extend({
fileInput.click();
}
}
if (this.imageSelector) {
this.scrollToCard();
}
},
actions: {

View File

@ -100,6 +100,7 @@
saveCard=(action card.env.save)
cancelCard=(action card.env.cancel)
removeCard=(action card.env.remove)
scrollToCard=(action "scrollToCard" card)
isSelected=card.isSelected
isEditing=card.isEditing
selectCard=(action "selectCard" card)

View File

@ -696,6 +696,11 @@ export default Component.extend({
this.deselectCard(card);
},
scrollToCard(card) {
this.selectCard(card);
this._scrollCursorIntoView({jumpToCard: true});
},
// range should be set to the full extent of the selection or the
// appropriate <a> markup. If there's a selection when the link edit
// component renders it will re-select when finished which should
@ -1475,7 +1480,15 @@ export default Component.extend({
if (atBottom) {
this._scrollContainer.scrollTop = this._scrollContainer.scrollHeight;
} else {
this._scrollContainer.scrollTop = scrollTop + offsetBottom + distanceFromViewportBottom + 20;
let scrollAdjustment = offsetBottom + distanceFromViewportBottom + 20;
let cursorFromTop = cursorTop - scrollAdjustment;
// pull top of cursor back into view if the adjustment pushed it off top of screen
if (cursorFromTop < 20) {
scrollAdjustment = scrollAdjustment + cursorFromTop - 20;
}
this._scrollContainer.scrollTop = scrollTop + scrollAdjustment;
}
}
}