Koenig - Fix triple-click select adding formatting to following paragraph

refs https://github.com/TryGhost/Ghost/issues/9623
- triple-click select will by default end the selection at position 0 of the following paragraph which means section-level formatting such as headers or quotes will affect the apparently unselected following paragraph
- add a guard to check for that selection situation and ensure the selection is constrained to the visibly selected text
This commit is contained in:
Kevin Ansfield 2018-05-14 15:13:47 +01:00
parent f03954679e
commit 505aee4dac

View File

@ -6,6 +6,7 @@
import Component from '@ember/component';
import Editor from 'mobiledoc-kit/editor/editor';
import EmberObject, {computed} from '@ember/object';
import MobiledocRange from 'mobiledoc-kit/utils/cursor/range';
import defaultAtoms from '../options/atoms';
import defaultCards from '../options/cards';
import layout from '../templates/components/koenig-editor';
@ -466,7 +467,7 @@ export default Component.extend({
},
cursorDidChange(editor) {
let {head, isCollapsed, head: {section}} = editor.range;
let {head, tail, direction, isCollapsed, head: {section}} = editor.range;
// sometimes we perform a programatic edit that causes a cursor change
// but we actually want to skip the default behaviour because we've
@ -522,6 +523,18 @@ export default Component.extend({
});
}
// do not include the tail section if it's offset is 0
// fixes triple-click unexpectedly selecting two sections for section-level formatting
// https://github.com/bustle/mobiledoc-kit/issues/597
if (direction === 1 && !isCollapsed && tail.offset === 0) {
let finalSection = tail.section.prev;
let newRange = new MobiledocRange(head, finalSection.tailPosition());
return editor.run((postEditor) => {
postEditor.setRange(newRange);
});
}
// pass the selected range through to the toolbar + menu components
this.set('selectedRange', editor.range);
},