Modified: trunk/Source/WebCore/ChangeLog (146614 => 146615)
--- trunk/Source/WebCore/ChangeLog 2013-03-22 15:16:27 UTC (rev 146614)
+++ trunk/Source/WebCore/ChangeLog 2013-03-22 15:22:50 UTC (rev 146615)
@@ -1,5 +1,34 @@
2013-03-22 Vsevolod Vlasov <[email protected]>
+ Web Inspector: Correctly implement scrollToLine, revealLine and setSelection on CodeMirror editor.
+ https://bugs.webkit.org/show_bug.cgi?id=113028
+
+ Reviewed by Pavel Feldman.
+
+ Added focus event handler to CodeMirror editor view elememnt to support inspector's focus model.
+ Added selection and scroll listeners to correctly save editor scroll and selection in history.
+ Implemented revealLine, scrollToLine and setSelection.
+ Note: CodeMirror's coordsChar method does not work correctly in "local" mode, implemented as binary search
+ as a temporary workaround.
+
+ * inspector/front-end/CodeMirrorTextEditor.js:
+ (WebInspector.CodeMirrorTextEditor):
+ (WebInspector.CodeMirrorTextEditor.prototype.defaultFocusedElement):
+ (WebInspector.CodeMirrorTextEditor.prototype._handleElementFocus):
+ (WebInspector.CodeMirrorTextEditor.prototype.revealLine):
+ (WebInspector.CodeMirrorTextEditor.prototype._coordsChar):
+ (WebInspector.CodeMirrorTextEditor.prototype._topScrolledLine):
+ (WebInspector.CodeMirrorTextEditor.prototype._bottomScrolledLine):
+ (WebInspector.CodeMirrorTextEditor.prototype._scroll):
+ (WebInspector.CodeMirrorTextEditor.prototype._selectionChange):
+ (WebInspector.CodeMirrorTextEditor.prototype.scrollToLine):
+ (WebInspector.CodeMirrorTextEditor.prototype.setSelection):
+ (WebInspector.CodeMirrorTextEditor.prototype.copyRange):
+ * inspector/front-end/TextEditor.js:
+ (WebInspector.TextEditor.prototype.copyRange):
+
+2013-03-22 Vsevolod Vlasov <[email protected]>
+
Web Inspector: [Regression] Editor scroll is not restored after inspector reload.
https://bugs.webkit.org/show_bug.cgi?id=113027
Modified: trunk/Source/WebCore/inspector/front-end/CodeMirrorTextEditor.js (146614 => 146615)
--- trunk/Source/WebCore/inspector/front-end/CodeMirrorTextEditor.js 2013-03-22 15:16:27 UTC (rev 146614)
+++ trunk/Source/WebCore/inspector/front-end/CodeMirrorTextEditor.js 2013-03-22 15:22:50 UTC (rev 146615)
@@ -75,6 +75,7 @@
this._codeMirror.on("change", this._change.bind(this));
this._codeMirror.on("gutterClick", this._gutterClick.bind(this));
this._codeMirror.on("cursorActivity", this._cursorActivity.bind(this));
+ this._codeMirror.on("scroll", this._scroll.bind(this));
this.element.addEventListener("contextmenu", this._contextMenu.bind(this));
this._lastRange = this.range();
@@ -83,6 +84,9 @@
this.element.firstChild.addStyleClass("fill");
this._elementToWidget = new Map();
this._nestedUpdatesCounter = 0;
+
+ this.element.addEventListener("focus", this._handleElementFocus.bind(this), false);
+ this.element.tabIndex = 0;
}
WebInspector.CodeMirrorTextEditor.prototype = {
@@ -150,7 +154,7 @@
*/
defaultFocusedElement: function()
{
- return this.element.firstChild;
+ return this.element;
},
focus: function()
@@ -158,6 +162,11 @@
this._codeMirror.focus();
},
+ _handleElementFocus: function()
+ {
+ this._codeMirror.focus();
+ },
+
beginUpdates: function()
{
++this._nestedUpdatesCounter;
@@ -174,8 +183,18 @@
*/
revealLine: function(lineNumber)
{
- this._codeMirror.setCursor({ line: lineNumber, ch: 0 });
- this._codeMirror.scrollIntoView();
+ var pos = CodeMirror.Pos(lineNumber, 0);
+ var topLine = this._topScrolledLine();
+ var bottomLine = this._bottomScrolledLine();
+
+ var margin = null;
+ var lineMargin = 3;
+ var scrollInfo = this._codeMirror.getScrollInfo();
+ if ((lineNumber < topLine + lineMargin) || (lineNumber >= bottomLine - lineMargin)) {
+ // scrollIntoView could get into infinite loop if margin exceeds half of the clientHeight.
+ margin = (scrollInfo.clientHeight*0.9/2) >>> 0;
+ }
+ this._codeMirror.scrollIntoView(pos, margin);
},
_gutterClick: function(instance, lineNumber, gutter, event)
@@ -339,12 +358,57 @@
this._delegate.selectionChanged(this._toRange(start, end));
},
+ _coordsCharLocal: function(coords)
+ {
+ var top = coords.top;
+ var totalLines = this._codeMirror.lineCount();
+ var begin = 0;
+ var end = totalLines - 1;
+ while (end - begin > 1) {
+ var middle = (begin + end) >> 1;
+ var coords = this._codeMirror.charCoords(CodeMirror.Pos(middle, 0), "local");
+ if (coords.top >= top)
+ end = middle;
+ else
+ begin = middle;
+ }
+
+ return end;
+ },
+
+ _topScrolledLine: function()
+ {
+ var scrollInfo = this._codeMirror.getScrollInfo();
+ // Workaround for CodeMirror's coordsChar incorrect result for "local" mode.
+ return this._coordsCharLocal(scrollInfo);
+ },
+
+ _bottomScrolledLine: function()
+ {
+ var scrollInfo = this._codeMirror.getScrollInfo();
+ scrollInfo.top += scrollInfo.clientHeight;
+ // Workaround for CodeMirror's coordsChar incorrect result for "local" mode.
+ return this._coordsCharLocal(scrollInfo);
+ },
+
+ _scroll: function()
+ {
+ this._delegate.scrollChanged(this._topScrolledLine());
+ },
+
/**
* @param {number} lineNumber
*/
scrollToLine: function(lineNumber)
{
- this._codeMirror.setCursor({line:lineNumber, ch:0});
+ function performScroll()
+ {
+ var pos = CodeMirror.Pos(lineNumber, 0);
+ var coords = this._codeMirror.charCoords(pos, "local");
+ this._codeMirror.scrollTo(0, coords.top);
+ }
+
+ setTimeout(performScroll.bind(this), 0);
},
/**
@@ -374,9 +438,14 @@
*/
setSelection: function(textRange)
{
- this._lastSelection = textRange;
- var pos = this._toPos(textRange);
- this._codeMirror.setSelection(pos.start, pos.end);
+ function performSelectionSet()
+ {
+ this._lastSelection = textRange;
+ var pos = this._toPos(textRange);
+ this._codeMirror.setSelection(pos.start, pos.end);
+ }
+
+ setTimeout(performSelectionSet.bind(this), 0);
},
/**
Modified: trunk/Source/WebCore/inspector/front-end/TextEditor.js (146614 => 146615)
--- trunk/Source/WebCore/inspector/front-end/TextEditor.js 2013-03-22 15:16:27 UTC (rev 146614)
+++ trunk/Source/WebCore/inspector/front-end/TextEditor.js 2013-03-22 15:22:50 UTC (rev 146615)
@@ -101,12 +101,6 @@
*/
setExecutionLine: function(lineNumber) { },
- /**
- * @param {WebInspector.TextRange} range
- * @return {string}
- */
- copyRange: function(range) { },
-
clearExecutionLine: function() { },
/**
@@ -177,6 +171,12 @@
setSelection: function(textRange) { },
/**
+ * @param {WebInspector.TextRange} range
+ * @return {string}
+ */
+ copyRange: function(range) { },
+
+ /**
* @param {string} text
*/
setText: function(text) { },