Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Triple-click + toggleSection affects visibly unselected section #597

Open
kevinansfield opened this issue Dec 18, 2017 · 2 comments
Open

Comments

@kevinansfield
Copy link
Collaborator

When triple-clicking on a paragraph or drag-selecting where the pointer is released just underneath the selected text, the selected range's tail ends up at offset 0 on the following section. Any subsequent use of editor.toggleSection applies the formatting to the visibly selected paragraph but also unexpectedly to the following paragraph.

I'm not sure if this is expected behaviour or a bug, if it's a bug is it in the cursor handling or the toggleSection implementation? Anyway, to work around this I had to add some extra logic to my editor.cursorDidChange event handler:

_cursorDidChange(editor) {
    let {head, tail, direction} = editor.range;

    // do not include the tail section if it's offset is 0
    // fixes triple-click unexpectedly selecting two sections for section-level formatting
    if (direction === 1 && !editor.range.isCollapsed && tail.offset === 0) {
        let prevSection = tail.section.prev;
        let newRange = new MobiledocKit.Range(head, prevSection.tailPosition());

        return editor.run(postEditor => {
            postEditor.setRange(newRange);
        });
    }

    if (!editor.range.isCollapsed) {
        set(this, 'hasSelection', true);
    } else {
        set(this, 'hasSelection', false);
    }
}

Editor: ember-mobiledoc-editor
Browser: Chrome 63/Safari 11 on MacOS 10.13.2 (High Sierra)

The extra selection is a little easier to see on Safari because the space between paragraphs is shown as selected. In Chrome (shown below) there's zero visual difference between selecting the just text of the paragraph and the selection expanding to offset 0 of the following section

mobiledoc-triple-click

@kevinansfield kevinansfield changed the title Triple-click + toggleSection affects visibly unselected next section Triple-click + toggleSection affects visibly unselected section Dec 18, 2017
@kevinansfield kevinansfield changed the title Triple-click + toggleSection affects visibly unselected section Triple-click+toggleSection affects visibly unselected section Dec 18, 2017
@kevinansfield kevinansfield changed the title Triple-click+toggleSection affects visibly unselected section Triple-click + toggleSection affects visibly unselected section Dec 18, 2017
@sdhull
Copy link

sdhull commented Jan 18, 2019

Yeah this strikes me as a bug, personally. My colleague just ran into it and was confounded.
Thanks for posting the work around 🙏

@whatthewhat
Copy link

I believe this was fixed by #713, just ran a quick test with 0.12.4 and can't reproduce it anymore 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants