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

Commit

Permalink
🐜 Bulk selecting (#594)
Browse files Browse the repository at this point in the history
closes: TryGhost/Ghost#8153

Previously when selecting text in the editor the screen will jump as it tries to scroll so that the cursor is always on it.

This update means it will no longer happen when selecting the text with either the mouse or in a mobile browser. Unfortunately when selecting text with the keyboard the editor will no longer scroll with the cursor.
  • Loading branch information
disordinary authored and kevinansfield committed Mar 20, 2017
1 parent 41b035d commit 98d2394
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions lib/gh-koenig/addon/components/gh-koenig.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,20 @@ export default Component.extend({
}
},

// makes sure the cursor is on screen.
// makes sure the cursor is on screen except when selection is happening in which case the browser mostly ensures it.
// there is an issue with keyboard selection on some browsers though so the next step will be to record mouse and touch events.
cursorMoved() {
let scrollBuffer = 33; // the extra buffer to scroll.
let range = window.getSelection().getRangeAt(0); // get the actual range within the DOM.
let position = range.getBoundingClientRect();
let windowHeight = window.innerHeight;

if (position.bottom > windowHeight) {
this.domContainer.scrollTop += position.bottom - windowHeight + scrollBuffer;
} else if (position.top < 0) {
this.domContainer.scrollTop += position.top - scrollBuffer;
if (this.get('editor').range.isCollapsed) {
let scrollBuffer = 33; // the extra buffer to scroll.
let range = window.getSelection().getRangeAt(0); // get the actual range within the DOM.
let position = range.getBoundingClientRect();
let windowHeight = window.innerHeight;

if (position.bottom > windowHeight) {
this.domContainer.scrollTop += position.bottom - windowHeight + scrollBuffer;
} else if (position.top < 0) {
this.domContainer.scrollTop += position.top - scrollBuffer;
}
}
},

Expand Down

0 comments on commit 98d2394

Please sign in to comment.