Commit d1aecf01 authored by graouts@apple.com's avatar graouts@apple.com

Web Inspector: evaluate and show a popover for selected text in JS source when paused

https://bugs.webkit.org/show_bug.cgi?id=122151

Reviewed by Joseph Pecoraro.

Identify if the hovered token is contained within the text selection (if any) and use
the selection as the hovered expression to allow the user to select text and hover it
to see what it evaluates to.

* UserInterface/CodeMirrorTokenTrackingController.js:
(WebInspector.CodeMirrorTokenTrackingController.prototype.highlightRange):
Check we're trying to highlight a different range before removing the highlight
and applying the new one, this prevents the marked text from flashing if it's
being re-hovered which would easily happen when hovering multiple tokens within
the same selection.

(WebInspector.CodeMirrorTokenTrackingController.prototype._processJavaScriptExpression):
In the case where there is selected text, check whether the hovered token is at least
partially contained within the selection, and if so use the selection text as the
hovered expression to evaluate.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@156728 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 0f949982
2013-10-01 Antoine Quint <graouts@apple.com>
Web Inspector: evaluate and show a popover for selected text in JS source when paused
https://bugs.webkit.org/show_bug.cgi?id=122151
Reviewed by Joseph Pecoraro.
Identify if the hovered token is contained within the text selection (if any) and use
the selection as the hovered expression to allow the user to select text and hover it
to see what it evaluates to.
* UserInterface/CodeMirrorTokenTrackingController.js:
(WebInspector.CodeMirrorTokenTrackingController.prototype.highlightRange):
Check we're trying to highlight a different range before removing the highlight
and applying the new one, this prevents the marked text from flashing if it's
being re-hovered which would easily happen when hovering multiple tokens within
the same selection.
(WebInspector.CodeMirrorTokenTrackingController.prototype._processJavaScriptExpression):
In the case where there is selected text, check whether the hovered token is at least
partially contained within the selection, and if so use the selection text as the
hovered expression to evaluate.
2013-10-01 Antoine Quint <graouts@apple.com>
Console buttons don’t show after page reload
......
......@@ -159,6 +159,14 @@ WebInspector.CodeMirrorTokenTrackingController.prototype = {
highlightRange: function(range)
{
// Nothing to do if we're trying to highlight the same range.
if (this._codeMirrorMarkedText && this._codeMirrorMarkedText.className === this._classNameForHighlightedRange) {
var highlightedRange = this._codeMirrorMarkedText.find();
if (WebInspector.compareCodeMirrorPositions(highlightedRange.from, range.start) === 0 &&
WebInspector.compareCodeMirrorPositions(highlightedRange.to, range.end) === 0)
return;
}
this.removeHighlightedRange();
var className = this._classNameForHighlightedRange || "";
......@@ -360,6 +368,32 @@ WebInspector.CodeMirrorTokenTrackingController.prototype = {
if (this._hoveredTokenInfo.modeName !== "javascript")
return null;
var startPosition = {line: this._hoveredTokenInfo.position.line, ch: this._hoveredTokenInfo.token.start};
var endPosition = {line: this._hoveredTokenInfo.position.line, ch: this._hoveredTokenInfo.token.end};
// If the hovered token is within a selection, use the selection as our expression.
if (this._codeMirror.somethingSelected()) {
var selectionRange = {
start: this._codeMirror.getCursor("start"),
end: this._codeMirror.getCursor("end")
};
function tokenIsInRange(token, range)
{
return token.line >= range.start.line && token.ch >= range.start.ch &&
token.line <= range.end.line && token.ch <= range.end.ch;
}
if (tokenIsInRange(startPosition, selectionRange) || tokenIsInRange(endPosition, selectionRange)) {
return {
hoveredToken: this._hoveredTokenInfo.token,
hoveredTokenRange: selectionRange,
expression: this._codeMirror.getSelection(),
expressionRange: selectionRange,
};
}
}
// We only handle vars, definitions, properties, and the keyword 'this'.
var type = this._hoveredTokenInfo.token.type;
var isProperty = type.indexOf("property") !== -1;
......@@ -379,8 +413,6 @@ WebInspector.CodeMirrorTokenTrackingController.prototype = {
// Work out the full hovered expression.
var expression = this._hoveredTokenInfo.token.string;
var expressionStartPosition = {line: this._hoveredTokenInfo.position.line, ch: this._hoveredTokenInfo.token.start};
var startPosition = {line: this._hoveredTokenInfo.position.line, ch: this._hoveredTokenInfo.token.start};
var endPosition = {line: this._hoveredTokenInfo.position.line, ch: this._hoveredTokenInfo.token.end};
while (true) {
var token = this._codeMirror.getTokenAt(expressionStartPosition);
var isDot = token && !token.type && token.string === ".";
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment