RESOLVED FIXED 31238
Web Inspector: Inspector should support copy() in the command line
https://bugs.webkit.org/show_bug.cgi?id=31238
Summary Web Inspector: Inspector should support copy() in the command line
Keishi Hattori
Reported Sunday, November 8, 2009 10:20:21 AM UTC
I found an undocumented but useful Firebug Command Line API, copy(). It copies the argument to the pasteboard.
Attachments
proposed patch (3.44 KB, patch)
2009-11-08 02:26 PST, Keishi Hattori
no flags
proposed patch 2 (10.48 KB, patch)
2009-11-08 02:37 PST, Keishi Hattori
pfeldman: review-
proposed patch 3 (10.90 KB, patch)
2009-11-08 21:14 PST, Keishi Hattori
pfeldman: review-
proposed patch 4 (10.90 KB, patch)
2009-11-08 22:16 PST, Keishi Hattori
no flags
Keishi Hattori
Comment 1 Sunday, November 8, 2009 10:26:00 AM UTC
Created attachment 42711 [details] proposed patch I had to use a horrific hack to get it to work. Is there a better way?
Keishi Hattori
Comment 2 Sunday, November 8, 2009 10:37:31 AM UTC
Created attachment 42713 [details] proposed patch 2 added comment and added line breaks to the eval string.
Pavel Feldman
Comment 3 Sunday, November 8, 2009 11:59:00 AM UTC
Comment on attachment 42713 [details] proposed patch 2 What you should do instead is: - Introduce copyText in InspectorBackend.(idl, h, cpp). Just mimic copyNode there and pass text instead of node id. - Implement it as Pasteboard::generalPasteboard()->writePlainText(text); (see copyNode again) - Make a simple call to it from your new copy API method. We could be even more cleaver here and copy markup in case selected object is node (make an instanceof check under copy and choose between copyText and copyNode to call). [object HTMLElement] is not too informative otherwise...
Keishi Hattori
Comment 4 Monday, November 9, 2009 4:32:16 AM UTC
(In reply to comment #3) > (From update of attachment 42713 [details]) > What you should do instead is: > - Introduce copyText in InspectorBackend.(idl, h, cpp). Just mimic copyNode > there and pass text instead of node id. > - Implement it as Pasteboard::generalPasteboard()->writePlainText(text); (see > copyNode again) > - Make a simple call to it from your new copy API method. > > We could be even more cleaver here and copy markup in case selected object is > node (make an instanceof check under copy and choose between copyText and > copyNode to call). [object HTMLElement] is not too informative otherwise… I was able to get the copyText method working. I wanted to use copyNode for nodes but I couldn't figure out how to get the node id from a node?
Pavel Feldman
Comment 5 Monday, November 9, 2009 4:55:14 AM UTC
(In reply to comment #4) > (In reply to comment #3) > > (From update of attachment 42713 [details] [details]) > > What you should do instead is: > > - Introduce copyText in InspectorBackend.(idl, h, cpp). Just mimic copyNode > > there and pass text instead of node id. > > - Implement it as Pasteboard::generalPasteboard()->writePlainText(text); (see > > copyNode again) > > - Make a simple call to it from your new copy API method. > > > > We could be even more cleaver here and copy markup in case selected object is > > node (make an instanceof check under copy and choose between copyText and > > copyNode to call). [object HTMLElement] is not too informative otherwise… > > I was able to get the copyText method working. I wanted to use copyNode for > nodes but I couldn't figure out how to get the node id from a node? Oh, sorry about the confusion. Actually, given that copy is executed in the injectedscript already, there is no need to go from id to node in order to copy it. Your argument is already a real node, no need to resolve it by id. But there is no copyNode(Node) method in InspectorBackend because it would be [Custom] and there were actually no use cases for it... I think you should either forget my suggestion about calling copyNode or do var nodeId = InspectorController.pushNodePathToFrontend(node, false /* selectInUI */); It would give you id for a node, but as a side affect it will also push it into the frontend in case it was not there. Which is actually fine.
Keishi Hattori
Comment 6 Monday, November 9, 2009 5:14:59 AM UTC
Created attachment 42730 [details] proposed patch 3 Thanks I get it now. So pushNodePathToFrontend does the mapping.
Pavel Feldman
Comment 7 Monday, November 9, 2009 5:43:53 AM UTC
Comment on attachment 42730 [details] proposed patch 3 > + void copyText(const String& text); > + > // Generic code called from custom implementations. > void highlight(long nodeId); Please move copyText into the "Generic code called from custom implementations." (under that comment). > + var inspectorCommandLineAPI = evalFunction.call(evalObject, "window.console._inspectorCommandLineAPI = { \n\ > + $: function() { return document.getElementById.apply(document, arguments) }, \n\ > + $$: function() { return document.querySelectorAll.apply(document, arguments) }, \n\ > + $x: function(xpath, context) \n\ > + { \n\ I assume that the only change here is \n in the end (please confirm)? r- for the copyText outside the injectedscript section, otherwise r+!
Pavel Feldman
Comment 8 Monday, November 9, 2009 5:51:24 AM UTC
Sorry, I meant to move copyText into the // Called from InjectedScript. // TODO: extract into a separate IDL. section in IDL, not custom in header... (Too early here, too much copypate).
Keishi Hattori
Comment 9 Monday, November 9, 2009 6:16:03 AM UTC
Created attachment 42734 [details] proposed patch 4 (In reply to comment #7) > I assume that the only change here is \n in the end (please confirm)? Changes to the eval string is \n and K&R style indentation.
WebKit Commit Bot
Comment 10 Monday, November 9, 2009 6:39:41 AM UTC
Comment on attachment 42734 [details] proposed patch 4 Clearing flags on attachment: 42734 Committed r50639: <http://trac.webkit.org/changeset/50639>
WebKit Commit Bot
Comment 11 Monday, November 9, 2009 6:39:46 AM UTC
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.