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

Commit

Permalink
Koenig - Fix triple-click select adding formatting to following parag…
Browse files Browse the repository at this point in the history
…raph

refs TryGhost/Ghost#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
  • Loading branch information
kevinansfield committed May 14, 2018
1 parent 41c1f63 commit 17b2b1a
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/koenig-editor/addon/components/koenig-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
},
Expand Down

0 comments on commit 17b2b1a

Please sign in to comment.