Bug 148368

Summary: Web Inspector: Command-Enter should evaluate selected JS in Debugger/Sources
Product: WebKit Reporter: Nikita Vasilyev <nvasilyev>
Component: Web InspectorAssignee: Nikita Vasilyev <nvasilyev>
Status: RESOLVED FIXED    
Severity: Normal CC: bburg, commit-queue, graouts, joepeck, mattbaker, nvasilyev, timothy, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Local Build   
Hardware: All   
OS: All   
Attachments:
Description Flags
Patch none

Description Nikita Vasilyev 2015-08-22 20:27:18 PDT
Light Table has an inline evaluation. Pressing Command-Enter runs the selected code and shows the return value inline, right by the code.
http://lighttable.com/#features

Chrome DevTools have a Control-Shift-E shortcut to evaluate selected text in the console.

I think, eventually we need to do something like Light Table. There are quite a few nuances and I could take while to get it right. So, for now, I propose to implement Command-Enter shortcut to evaluate the selected code in the console.
Comment 1 Radar WebKit Bug Importer 2015-08-22 20:27:46 PDT
<rdar://problem/22393224>
Comment 2 Nikita Vasilyev 2015-08-26 02:45:58 PDT
Created attachment 259942 [details]
Patch
Comment 3 Timothy Hatcher 2015-08-26 02:51:03 PDT
Comment on attachment 259942 [details]
Patch

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

> Source/WebInspectorUI/UserInterface/Controllers/CodeMirrorCompletionController.js:730
> +        if (modeName !== "javascript" && modeName !== "htmlmixed")

I think there is a way to get the inner mode for the selection, that way we know if it is JS even inside html. Right now I think that will allow non-JS to be evaluated from HTML. The completion controller has code for looking at inner mode I think.
Comment 4 Timothy Hatcher 2015-08-26 02:51:26 PDT
Comment on attachment 259942 [details]
Patch

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

>> Source/WebInspectorUI/UserInterface/Controllers/CodeMirrorCompletionController.js:730
>> +        if (modeName !== "javascript" && modeName !== "htmlmixed")
> 
> I think there is a way to get the inner mode for the selection, that way we know if it is JS even inside html. Right now I think that will allow non-JS to be evaluated from HTML. The completion controller has code for looking at inner mode I think.

Oh, now I see your comment in the ChangeLog. Sounds good.
Comment 5 Nikita Vasilyev 2015-08-26 02:57:20 PDT
(In reply to comment #4)
> Comment on attachment 259942 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=259942&action=review
> 
> >> Source/WebInspectorUI/UserInterface/Controllers/CodeMirrorCompletionController.js:730
> >> +        if (modeName !== "javascript" && modeName !== "htmlmixed")
> > 
> > I think there is a way to get the inner mode for the selection, that way we know if it is JS even inside html. Right now I think that will allow non-JS to be evaluated from HTML. The completion controller has code for looking at inner mode I think.
> 
> Oh, now I see your comment in the ChangeLog. Sounds good.

Currently, pressing Command-Enter inside a resource doesn't do anything at all. It doesn't insert a new line. We may revisit what does it do for HTML in the future, but I don't have any other ideas at the moment.
Comment 6 WebKit Commit Bot 2015-08-26 09:06:38 PDT
Comment on attachment 259942 [details]
Patch

Clearing flags on attachment: 259942

Committed r188967: <http://trac.webkit.org/changeset/188967>
Comment 7 WebKit Commit Bot 2015-08-26 09:06:46 PDT
All reviewed patches have been landed.  Closing bug.
Comment 8 Nikita Vasilyev 2015-09-14 01:55:33 PDT
Looking into this two weeks later with a fresh eye, I think Command-Enter should show the exact same popover as on hover. Evaluating in the console seems too disconnected from the source code and requires a bit of an extra mental effort not to lose the context.