Bug 90611

Summary: contenteditable justify commands applied to next paragraph as well
Product: WebKit Reporter: Sijmen Mulder <sjmulder>
Component: New BugsAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: buildbot, commit-queue, rniwa, santosh.ma
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: All   
OS: All   
Attachments:
Description Flags
Sample case
none
Hacky workaround
none
Work in progress
none
Archive of layout-test-results from webkit-ews-15 for mac-mountainlion-wk2
none
Archive of layout-test-results from webkit-ews-03 for mac-mountainlion
none
work in progress
none
Archive of layout-test-results from webkit-ews-09 for mac-mountainlion-wk2
none
Archive of layout-test-results from webkit-ews-05 for mac-mountainlion
none
WIP
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch for Landing none

Sijmen Mulder
Reported 2012-07-05 07:50:04 PDT
Created attachment 150937 [details] Sample case When executing the justifyLeft, justifyRight or justifyFull command when a paragraph is selected in a contenteidtable element, the justification is applied to the paragraph after the selected paragraph as well. Steps to reproduce: 1. Create a contenteditable element. 2. Have three paragraphs as its contents: <p>Paragraph one</p><p>Paragraph two</p><p>Paragraph three</p> 3. Select the first paragraph by triple-clicking on it or by dragging down from the start of the paragraph to the start of the next paragraph. 4. Call document.execCommand('justfiyRight', false, null) Expected results: * The first paragraph is justified to the right. Actual results: * The first and second paragraphs are both justified to the right, even though the second was not selected. Note that if the paragraph is only selected up to and including the final character, and not the newline, the justification works correctly. I’ve done some digging and this is what I’ve found: when a paragraph is selected in its entirely, the selection range (window.getSelection().range) extends until position 0 of the next paragraph. Perhaps that’s why the justification is applied to that paragraph as well, however, it’s not the user intention. Find attached a sample page that demonstrates the issue.
Attachments
Sample case (579 bytes, text/html)
2012-07-05 07:50 PDT, Sijmen Mulder
no flags
Hacky workaround (1.12 KB, application/x-javascript)
2012-07-10 03:24 PDT, Sijmen Mulder
no flags
Work in progress (1.66 KB, patch)
2013-09-29 05:15 PDT, Santosh Mahto
no flags
Archive of layout-test-results from webkit-ews-15 for mac-mountainlion-wk2 (836.18 KB, application/zip)
2013-09-29 06:03 PDT, Build Bot
no flags
Archive of layout-test-results from webkit-ews-03 for mac-mountainlion (887.17 KB, application/zip)
2013-09-29 06:25 PDT, Build Bot
no flags
work in progress (1.63 KB, patch)
2013-09-30 00:16 PDT, Santosh Mahto
no flags
Archive of layout-test-results from webkit-ews-09 for mac-mountainlion-wk2 (464.58 KB, application/zip)
2013-09-30 01:04 PDT, Build Bot
no flags
Archive of layout-test-results from webkit-ews-05 for mac-mountainlion (540.28 KB, application/zip)
2013-09-30 02:08 PDT, Build Bot
no flags
WIP (1.68 KB, patch)
2013-09-30 08:44 PDT, Santosh Mahto
no flags
Patch (4.99 KB, patch)
2013-09-30 10:12 PDT, Santosh Mahto
no flags
Patch (5.31 KB, patch)
2013-10-01 10:15 PDT, Santosh Mahto
no flags
Patch (5.32 KB, patch)
2013-10-01 10:38 PDT, Santosh Mahto
no flags
Patch (5.39 KB, patch)
2013-10-01 12:32 PDT, Santosh Mahto
no flags
Patch for Landing (5.35 KB, patch)
2013-10-01 21:18 PDT, Santosh Mahto
no flags
Sijmen Mulder
Comment 1 2012-07-10 03:24:30 PDT
Created attachment 151425 [details] Hacky workaround I’ve attached a sort of hacky workaround with a function that can be called to adjust the selection before performing the justify* commands.
Santosh Mahto
Comment 2 2013-09-29 05:15:55 PDT
Created attachment 212925 [details] Work in progress
Build Bot
Comment 3 2013-09-29 06:03:24 PDT
Comment on attachment 212925 [details] Work in progress Attachment 212925 [details] did not pass mac-wk2-ews (mac-wk2): Output: http://webkit-queues.appspot.com/results/2761018 New failing tests: editing/execCommand/justify.html editing/style/create-block-for-style-013.html editing/style/create-block-for-style-002.html editing/execCommand/25320.html editing/execCommand/5080333-1.html editing/style/4230923.html editing/execCommand/5062376.html editing/style/create-block-for-style-003.html editing/execCommand/25256.html editing/deleting/delete-start-block.html editing/execCommand/15381.html editing/execCommand/5080333-2.html
Build Bot
Comment 4 2013-09-29 06:03:27 PDT
Created attachment 212926 [details] Archive of layout-test-results from webkit-ews-15 for mac-mountainlion-wk2 The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews. Bot: webkit-ews-15 Port: mac-mountainlion-wk2 Platform: Mac OS X 10.8.5
Build Bot
Comment 5 2013-09-29 06:25:23 PDT
Comment on attachment 212925 [details] Work in progress Attachment 212925 [details] did not pass mac-ews (mac): Output: http://webkit-queues.appspot.com/results/2699026 New failing tests: editing/execCommand/justify.html editing/style/create-block-for-style-013.html editing/style/create-block-for-style-002.html editing/execCommand/25320.html editing/execCommand/5080333-1.html editing/style/4230923.html editing/execCommand/5062376.html editing/style/create-block-for-style-003.html editing/execCommand/25256.html editing/deleting/delete-start-block.html editing/execCommand/15381.html editing/execCommand/5080333-2.html
Build Bot
Comment 6 2013-09-29 06:25:25 PDT
Created attachment 212928 [details] Archive of layout-test-results from webkit-ews-03 for mac-mountainlion The attached test failures were seen while running run-webkit-tests on the mac-ews. Bot: webkit-ews-03 Port: mac-mountainlion Platform: Mac OS X 10.8.5
Santosh Mahto
Comment 7 2013-09-30 00:16:13 PDT
Created attachment 212956 [details] work in progress
Build Bot
Comment 8 2013-09-30 01:04:56 PDT
Comment on attachment 212956 [details] work in progress Attachment 212956 [details] did not pass mac-wk2-ews (mac-wk2): Output: http://webkit-queues.appspot.com/results/2804073 New failing tests: editing/execCommand/align-in-span.html
Build Bot
Comment 9 2013-09-30 01:04:57 PDT
Created attachment 212958 [details] Archive of layout-test-results from webkit-ews-09 for mac-mountainlion-wk2 The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews. Bot: webkit-ews-09 Port: mac-mountainlion-wk2 Platform: Mac OS X 10.8.5
Build Bot
Comment 10 2013-09-30 02:08:21 PDT
Comment on attachment 212956 [details] work in progress Attachment 212956 [details] did not pass mac-ews (mac): Output: http://webkit-queues.appspot.com/results/2769019 New failing tests: editing/execCommand/align-in-span.html
Build Bot
Comment 11 2013-09-30 02:08:23 PDT
Created attachment 212963 [details] Archive of layout-test-results from webkit-ews-05 for mac-mountainlion The attached test failures were seen while running run-webkit-tests on the mac-ews. Bot: webkit-ews-05 Port: mac-mountainlion Platform: Mac OS X 10.8.5
Santosh Mahto
Comment 12 2013-09-30 08:44:05 PDT
Santosh Mahto
Comment 13 2013-09-30 10:12:05 PDT
Santosh Mahto
Comment 14 2013-09-30 10:38:46 PDT
The patch is completed. please review it
Darin Adler
Comment 15 2013-09-30 11:55:38 PDT
Comment on attachment 213010 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=213010&action=review > Source/WebCore/editing/ApplyStyleCommand.cpp:274 > + VisiblePosition beyondEnd((visibleEnd.deepEquivalent().deprecatedEditingOffset() || visibleEnd == paragraphStart) ? endOfParagraph(visibleEnd).next() : visibleEnd); Can you do this without using anything with “deprecated” in its name?
Ryosuke Niwa
Comment 16 2013-09-30 12:44:14 PDT
Comment on attachment 213010 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=213010&action=review > Source/WebCore/ChangeLog:18 > + (WebCore::ApplyStyleCommand::applyBlockStyle):Ignore the justify > + command for paragraph if selection is not part of it. Part of what? >> Source/WebCore/editing/ApplyStyleCommand.cpp:274 >> + VisiblePosition beyondEnd((visibleEnd.deepEquivalent().deprecatedEditingOffset() || visibleEnd == paragraphStart) ? endOfParagraph(visibleEnd).next() : visibleEnd); > > Can you do this without using anything with “deprecated” in its name? This change doesn't make much sense. What does the deprecated editing offset being non-zero to do with visibleEnd == paragraphStart? > LayoutTests/editing/execCommand/contenteditable-justify-next-paragraph.html:4 > +<script type="text/javascript"> There is no need to specify type in HTML5. > LayoutTests/editing/execCommand/contenteditable-justify-next-paragraph.html:12 > + var elem1 = document.getElementById("p1"); > + var elem2 = document.getElementById("p2"); Please don't use abbreviations like elem and p. Spell out words. > LayoutTests/editing/execCommand/contenteditable-justify-next-paragraph.html:14 > + var selection = window.getSelection(); > + selection.setBaseAndExtent(elem1, 0, elem2, 0); There is no need for the local variable here and "window.". > LayoutTests/editing/execCommand/contenteditable-justify-next-paragraph.html:18 > + document.getElementById("result").innerHTML= "Final Result:<br>" + "1st Paragraph: " + elem1.getAttribute("style") + "<br>" + str; Why isn't this using dump-as-markup or js-test-pre.js? > LayoutTests/editing/execCommand/contenteditable-justify-next-paragraph.html:30 > +<p id="result"> </p> Why do we have a space here?
Santosh Mahto
Comment 17 2013-10-01 10:15:49 PDT
Santosh Mahto
Comment 18 2013-10-01 10:29:13 PDT
> > >> Source/WebCore/editing/ApplyStyleCommand.cpp:274 > >> + VisiblePosition beyondEnd((visibleEnd.deepEquivalent().deprecatedEditingOffset() || visibleEnd == paragraphStart) ? endOfParagraph(visibleEnd).next() : visibleEnd); > > > > Can you do this without using anything with “deprecated” in its name? I changed the code. > > This change doesn't make much sense. What does the deprecated editing offset being non-zero to do with visibleEnd == paragraphStart? I changed the code its now visibleEnd != visibleStart. ApplyBlockElementCommand::doApply() : already has same adjustment for paragraph break. Same adjustment is done here. I updated the testcase align-in-expected.txt as it was failing for this change. I found on http://trac.webkit.org/changeset/50433 this test is for crash test. and expected txt has not much significance.
Santosh Mahto
Comment 19 2013-10-01 10:38:56 PDT
Ryosuke Niwa
Comment 20 2013-10-01 11:22:39 PDT
Comment on attachment 213098 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=213098&action=review The code change looks much better but still r- because there are many stylistic issues with the patch, and descriptions in change log entries need to be revised. > Source/WebCore/ChangeLog:9 > + end reaches upto next node with offset 0 just to include the I don't know what you mean by "reaches up to next node with offset 0". > Source/WebCore/ChangeLog:11 > + paragraph element who falls under selection causing next unselected Typo: two spaces before "who". > Source/WebCore/editing/ApplyStyleCommand.cpp:274 > + // When a selection ends at the start of a paragraph and is range selection, style should not be applied to that paragraph This comment repeats the code below. Please remove it. > LayoutTests/ChangeLog:10 > + TestCases verifying that range selection having end > + selection as paragraph and offset 0 should be ignored while > + treating as Justify candidate. Why is "TestCases" camel case? Also, this doesn't explain the end-user behavior. e.g. Add a test for selecting one paragraph and the beginning of another paragraph to ensure that only the first fully-selected paragraph should be justified when justifying the selection. > LayoutTests/editing/execCommand/contenteditable-justify-next-paragraph.html:10 > + <p id="p1">Paragraph one.</p> > + <p id="p2">Paragraph two.</p> Please don't use abbreviations like p. Spell out paragraph. > LayoutTests/editing/execCommand/contenteditable-justify-next-paragraph.html:17 > + var firstPara= document.getElementById("p1"); > + var secondPara = document.getElementById("p2"); > + getSelection().setBaseAndExtent(firstPara, 0, secondPara, 0); A much better way of accomplishing the same effect is to use getSelection().modify as in: document.getElementById('container').focus(); getSelection().modify('Extend', 'Forward', 'Line'); > LayoutTests/editing/execCommand/contenteditable-justify-next-paragraph.html:20 > + Markup.description('Only first Paragraph with id "p1" should have attribute style="text-align: center"'); We should also explain what we're testing here. Otherwise, it won't be obvious as to why the output should be what's explained here.
Santosh Mahto
Comment 21 2013-10-01 12:32:06 PDT
Santosh Mahto
Comment 22 2013-10-01 21:18:34 PDT
Created attachment 213150 [details] Patch for Landing
WebKit Commit Bot
Comment 23 2013-10-01 22:10:23 PDT
Comment on attachment 213150 [details] Patch for Landing Clearing flags on attachment: 213150 Committed r156764: <http://trac.webkit.org/changeset/156764>
WebKit Commit Bot
Comment 24 2013-10-01 22:10:26 PDT
All reviewed patches have been landed. Closing bug.
Note You need to log in before you can comment on or make changes to this bug.