RESOLVED FIXED 179042
Web Inspector: add contextmenu item to arbitrarily add HTML/Child to DOMTree
https://bugs.webkit.org/show_bug.cgi?id=179042
Summary Web Inspector: add contextmenu item to arbitrarily add HTML/Child to DOMTree
Devin Rousso
Reported 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".
Attachments
Patch (12.85 KB, patch)
2017-11-03 01:48 PDT, Devin Rousso
no flags
[Image] After Patch is applied (79.27 KB, image/png)
2017-11-03 01:49 PDT, Devin Rousso
no flags
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
Patch (18.41 KB, patch)
2017-11-03 20:58 PDT, Devin Rousso
no flags
Patch (18.47 KB, patch)
2017-11-04 00:29 PDT, Devin Rousso
no flags
Devin Rousso
Comment 1 2017-11-03 01:48:50 PDT
Devin Rousso
Comment 2 2017-11-03 01:49:09 PDT
Created attachment 325878 [details] [Image] After Patch is applied
Build Bot
Comment 3 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
Build Bot
Comment 4 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
Joseph Pecoraro
Comment 5 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.
Devin Rousso
Comment 6 2017-11-03 20:58:59 PDT
Joseph Pecoraro
Comment 7 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?
Joseph Pecoraro
Comment 8 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.
Devin Rousso
Comment 9 2017-11-04 00:29:40 PDT
WebKit Commit Bot
Comment 10 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>
WebKit Commit Bot
Comment 11 2017-11-04 01:03:41 PDT
All reviewed patches have been landed. Closing bug.
Radar WebKit Bug Importer
Comment 12 2017-11-15 12:31:03 PST
Note You need to log in before you can comment on or make changes to this bug.