New issue
Advanced search Search tips

Issue 764489 link

Starred by 1 user

Issue metadata

Status: Untriaged
Owner: ----
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 3
Type: Bug

Blocking:
issue 752672



Sign in to add a comment

Editing commands shouldn't assume same plain text index range after formatting

Project Member Reported by xiaoche...@chromium.org, Sep 12 2017

Issue description

What steps will reproduce the problem?

(1) Create HTML <pre contenteditable>foo\n\nbar\n\nbaz</pre> (available at https://jsfiddle.net/6yj5vwnx/1/)

(2) Select "foo\n\nbar\n\n"

(3) Run document.execCommand('formatBlock', false, 'div') (or press the "format" button)

What is the expected result?

The ending selection is "foo\nbar"

What happens instead?

The ending selection is "foo\nbar\nb"


The cause is that, ApplyBlockElementCommand::DoApply computes the plain text index range of the formatting range before inserting <div> with TextIterator, and applies the same plain text index range as the ending selection. However, 'formatblock div' removes some '\n' from the format range, shortening its plain text length.

The same pattern is observed in some other places in editing commands, all of which may have similar bugs.

The bug can be even worse if we start to change TextIterator's behavior to make it spec-compliant. We might also find a lot of similar failures when LayoutNG is enabled, where a different version of TextIterator is used.
 

Comment 1 by yosin@chromium.org, Sep 13 2017

It seems we should use Range object to track selection change instead of 
indexForVisiblePosition().

If we really want to use |indexForVisiblePosition()|, we should use |PlainTextRange|,
but this is not good option.

Also, I think we should get rid of |indexForVisiblePosition()|.

There are three places using |indexForVisiblePosition()|:
 - ApplyBlockElementCommand::DoApply(); actually uses |indexForVisiblePosition()| twice for start and end of selection
 - InsertListCommand::DoApply(); ditto
 - ToVisiblePosition() in AXLayoutObject; used for setting FrameSelection from AXARange in
OnNativeSetSelectionAction()




Comment 2 by yosin@chromium.org, Jan 10 2018

Labels: Pri-3
Project Member

Comment 3 by sheriffbot@chromium.org, Jan 10

Labels: Hotlist-Recharge-Cold
Status: Untriaged (was: Available)
This issue has been Available for over a year. If it's no longer important or seems unlikely to be fixed, please consider closing it out. If it is important, please re-triage the issue.

Sorry for the inconvenience if the bug really should have been left as Available.

For more details visit https://www.chromium.org/issue-tracking/autotriage - Your friendly Sheriffbot

Sign in to add a comment