Draft-js: Incorrect selection when selecting using dbl-click

Created on 20 May 2016  路  7Comments  路  Source: facebook/draft-js

If I select a block the test in editor by double click the end key is first character of next block.

bug

Most helpful comment

Hi @hellendag,

Please find the gif (here size of selected blocks is number of blocks selected):

draft_issue

All 7 comments

Can you provide a video or GIF? I'm not able to repro this.

Hi @hellendag,

Please find the gif (here size of selected blocks is number of blocks selected):

draft_issue

this is definitely a very common user behavior and a real issue

Hi! I'm also running into this issue (double clicking a block can lead to the end key overlapping into the next block).
I'm currently handling it by doing an extra check:

const selection = editorState.getSelection();
const startKey = selection.getStartKey();
const endKey = selection.getEndKey();
const selectionEnd = selection.getEndOffset();
const nextKey = editorState.getCurrentContent().getKeyAfter(startKey);

if (startKey === endKey || (selectionEnd === 0 && endKey === nextKey)) {
    // The user only meant to select one block
}

Checking in 2 years after this was first posted: any resolutions here?

(I don't have the same exact issue, but double clicking on text inside a block to select the whole text is giving incorrect offsets - they are based on where the double click started)

(Update: the above behavior is on triple-click actually)

Note that this works fine in Firefox, so it looks like a WebKit-specific issue.

Seeing this issue as well, but with a triple click to select everything in the current block. The selectionState focusOffset is set to the next block, at 0

Was this page helpful?
0 / 5 - 0 ratings