Bug 179042 - Web Inspector: add contextmenu item to arbitrarily add HTML/Child to DOMTree
Summary: Web Inspector: add contextmenu item to arbitrarily add HTML/Child to DOMTree
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (show other bugs)
Version: WebKit Nightly Build
Hardware: All All
: P2 Normal
Assignee: Devin Rousso
URL:
Keywords: InRadar
Depends on: 178996
Blocks: 179283
  Show dependency treegraph
 
Reported: 2017-10-30 18:03 PDT by Devin Rousso
Modified: 2017-11-15 12:31 PST (History)
5 users (show)

See Also:


Attachments
Patch (12.85 KB, patch)
2017-11-03 01:48 PDT, Devin Rousso
no flags Details | Formatted Diff | Diff
[Image] After Patch is applied (79.27 KB, image/png)
2017-11-03 01:49 PDT, Devin Rousso
no flags Details
Archive of layout-test-results from ews115 for mac-elcapitan (1.78 MB, application/zip)
2017-11-03 03:08 PDT, Build Bot
no flags Details
Patch (18.41 KB, patch)
2017-11-03 20:58 PDT, Devin Rousso
no flags Details | Formatted Diff | Diff
Patch (18.47 KB, patch)
2017-11-04 00:29 PDT, Devin Rousso
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Devin Rousso 2017-10-30 18:03:54 PDT
It would be useful to have an "Add > HTML" button that lets the user input whatever HTML they want.  The same is true of "Add > Previous Sibling" and "Add > Next Sibling".
Comment 1 Devin Rousso 2017-11-03 01:48:50 PDT
Created attachment 325877 [details]
Patch
Comment 2 Devin Rousso 2017-11-03 01:49:09 PDT
Created attachment 325878 [details]
[Image] After Patch is applied
Comment 3 Build Bot 2017-11-03 03:08:03 PDT
Comment on attachment 325877 [details]
Patch

Attachment 325877 [details] did not pass mac-debug-ews (mac):
Output: http://webkit-queues.webkit.org/results/5088065

New failing tests:
imported/blink/fast/text/international-iteration-simple-text.html
Comment 4 Build Bot 2017-11-03 03:08:04 PDT
Created attachment 325879 [details]
Archive of layout-test-results from ews115 for mac-elcapitan

The attached test failures were seen while running run-webkit-tests on the mac-debug-ews.
Bot: ews115  Port: mac-elcapitan  Platform: Mac OS X 10.11.6
Comment 5 Joseph Pecoraro 2017-11-03 12:19:09 PDT
Comment on attachment 325877 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=325877&action=review

r- for a couple reasons:

  • Should mark an undoable state somewhere to work well with undo/redo
  • If you have a <h3>Test</h3> and "add child" the element expands but still has the inline text content, this should probably be broken out like a normal element with non-1-inline-text-child

Other than those, this feels really great!

---

Enhancement ideas: (could happen now, or later, or never, up to you)

Since `Esc` will cause editing to cancel easily, I think we can provide some initial values to save users some typing.

What do you think of these simple starters:

  • Insert child of <ul>/<ol> could pre-populate with "<li>|</li>"
  • Insert sibling of <li> could pre-populate with "<li>|</li>"
  • Insert child of <tr> could pre-populate with "<td>|</td>"
  • Insert sibling of <td> could pre-populate with "<td>|</td>"
  • Insert child of <table> could pre-populate with "<tr>|</tr>"

We could even show that in the menu items like:

  Add > Child (<li>)
        Previous Sibling
        Next Sibling

We could event extend to detecting a near-by pattern:

  Add > Child (<div class="section">)
        Previous Sibling
        Next Sibling

  Add > Child
        Previous Sibling (<li class="item">)
        Next Sibling  (<li class="item">)

For example if the element has >2 siblings and >50% of the element's siblings have a common class name.

Other potential improvements:

  • Disallow adding a child of <script>, <style> as that is probably not what users intend
  • Disallow adding a child of <link>, <img>, <hr>, <br> and other elements expecting to not have children

At some point this gets to be "too smart" and ends up hurting usability. But I think keeping it simple will save developers some time.

> Source/WebInspectorUI/ChangeLog:3
> +        Web Inspector: add contextmenu item to arbitrarily add HTML/Child to DOMTree

Maybe "Add" should now be "Append"? That seems more natural for the majority of the items (Child, Sibling) and isn't too bad for the remaining (Attribute). But "Add" seems fine if you don't want to change.

> Source/WebInspectorUI/ChangeLog:13
> +        Call-through for `insertAdjacentHTML` on the corresponding node in the inspected page.

Typo?: "Call-through for" => "Call-through to"

> Source/WebInspectorUI/UserInterface/Models/DOMNode.js:508
> +        WI.RemoteObject.resolveNode(this).then((object) => {

r- because I think this won't work as expected with undo, but that should be easy to fix.

I think you want to be doing _makeUndoableCallback somewhere around here, or at least marking an undoable state.

> Source/WebInspectorUI/UserInterface/Models/DOMNode.js:509
> +            function inspectedPage_node_insertAdjacentHTML(position, html) {

\o/ great naming.

> Source/WebInspectorUI/UserInterface/Views/DOMTreeElement.js:1602
> +        if (position === "afterbegin" || position === "beforeend") {
> +            this.hasChildren = true;
> +            this.shouldRefreshChildren = true;
> +            this.expand();
> +        }

You might have to updateTitle around here if you have an element currently displaying with inline text. For example <h3>Test</h3> and you want to insert adjacent HTML to it.
Comment 6 Devin Rousso 2017-11-03 20:58:59 PDT
Created attachment 326013 [details]
Patch
Comment 7 Joseph Pecoraro 2017-11-03 22:19:53 PDT
Comment on attachment 326013 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=326013&action=review

Nice!

> Source/WebInspectorUI/UserInterface/Models/DOMNode.js:515
> +            DOMAgent.markUndoableState();
> +            object.callFunction(inspectedPage_node_insertAdjacentHTML, [position, html]);
> +            object.release();

All of the other cases seem to set the undoable state AFTER applying the change. So I think this should be:

    object.callFunction(inspectedPage_node_insertAdjacentHTML, [position, html], () => {
        DOMAgent.markUndoableState();
        object.release();
    });

What do you think?
Comment 8 Joseph Pecoraro 2017-11-03 22:21:16 PDT
Comment on attachment 326013 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=326013&action=review

>> Source/WebInspectorUI/UserInterface/Models/DOMNode.js:515
>> +            object.release();
> 
> All of the other cases seem to set the undoable state AFTER applying the change. So I think this should be:
> 
>     object.callFunction(inspectedPage_node_insertAdjacentHTML, [position, html], () => {
>         DOMAgent.markUndoableState();
>         object.release();
>     });
> 
> What do you think?

Err I suppose the object.release() can still happen like it currently does, but I still think the mark undoable state should happen AFTER the change.
Comment 9 Devin Rousso 2017-11-04 00:29:40 PDT
Created attachment 326023 [details]
Patch
Comment 10 WebKit Commit Bot 2017-11-04 01:03:36 PDT
Comment on attachment 326023 [details]
Patch

Clearing flags on attachment: 326023

Committed r224456: <https://trac.webkit.org/changeset/224456>
Comment 11 WebKit Commit Bot 2017-11-04 01:03:41 PDT
All reviewed patches have been landed.  Closing bug.
Comment 12 Radar WebKit Bug Importer 2017-11-15 12:31:03 PST
<rdar://problem/35567688>