Commit 13b82ef5 authored by podivilov@chromium.org's avatar podivilov@chromium.org
Browse files

2011-04-07 Pavel Podivilov <podivilov@chromium.org>

        Reviewed by Pavel Feldman.

        Web Inspector: update breakpoints according to source frame decorations after live edit.
        https://bugs.webkit.org/show_bug.cgi?id=58029

        * inspector/debugger/live-edit-expected.txt:
        * inspector/debugger/live-edit.html:
2011-04-07  Pavel Podivilov  <podivilov@chromium.org>

        Reviewed by Pavel Feldman.

        Web Inspector: update breakpoints according to source frame decorations after live edit.
        https://bugs.webkit.org/show_bug.cgi?id=58029

        * inspector/front-end/DebuggerPresentationModel.js:
        (WebInspector.DebuggerPresentationModel.prototype.editScriptSource.didEditScriptSource):
        (WebInspector.DebuggerPresentationModel.prototype.editScriptSource):
        (WebInspector.DebuggerPresentationModel.prototype._updateResourceContent.didEditScriptSource):
        (WebInspector.DebuggerPresentationModel.prototype._updateResourceContent):
        * inspector/front-end/SourceFile.js:
        (WebInspector.SourceFile.prototype.set content):
        * inspector/front-end/SourceFrame.js:
        (WebInspector.SourceFrame.prototype._handleSave.didEditScriptSource):
        (WebInspector.SourceFrame.prototype._handleSave):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@83294 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent bb843073
2011-04-07 Pavel Podivilov <podivilov@chromium.org>
Reviewed by Pavel Feldman.
Web Inspector: update breakpoints according to source frame decorations after live edit.
https://bugs.webkit.org/show_bug.cgi?id=58029
* inspector/debugger/live-edit-expected.txt:
* inspector/debugger/live-edit.html:
2011-04-08 Steve Block <steveblock@google.com>
 
Unreviewed build fix.
......@@ -21,5 +21,7 @@ Call stack:
4) InjectedScript._evaluateAndWrap (:265)
5) InjectedScript.evaluate (:245)
Script execution resumed.
Running: testBreakpointsUpdated
Debugger was disabled.
......@@ -18,8 +18,7 @@ function test()
function didShowScriptSource(sourceFrame)
{
InspectorTest.addSniffer(WebInspector.debuggerModel, "_didEditScriptSource", didEditScriptSource);
replaceInSource(sourceFrame, "return 0;", "return \"live-edited string\";");
replaceInSource(sourceFrame, "return 0;", "return \"live-edited string\";", didEditScriptSource);
}
function didEditScriptSource()
......@@ -47,8 +46,7 @@ function test()
function paused(callFrames)
{
InspectorTest.addSniffer(WebInspector.debuggerModel, "_didEditScriptSource", didEditScriptSource);
replaceInSource(panel.visibleView, "return 1;", "return 2;\n\n\n\n");
replaceInSource(panel.visibleView, "return 1;", "return 2;\n\n\n\n", didEditScriptSource);
}
function didEditScriptSource()
......@@ -62,15 +60,52 @@ function test()
InspectorTest.assertEquals("3", result.description, "edited function returns wrong result");
next();
}
},
function testBreakpointsUpdated(next)
{
InspectorTest.showScriptSource("edit-me.js", didShowScriptSource);
function didShowScriptSource(sourceFrame)
{
InspectorTest.addSniffer(sourceFrame, "addBreakpoint", breakpointAdded);
InspectorTest.setBreakpoint(sourceFrame, 2, "", true);
}
function breakpointAdded()
{
replaceInSource(panel.visibleView, "function f()", "function newFunctionCreatedWithLiveEdit()\n{\n}\nfunction f()", didEditScriptSource);
}
function didEditScriptSource()
{
var breakpoints = panel.visibleView._breakpoints;
for (var lineNumber in breakpoints)
InspectorTest.assertEquals("5", lineNumber);
next();
}
}
]);
function replaceInSource(sourceFrame, string, replacement)
function replaceInSource(sourceFrame, string, replacement, callback)
{
InspectorTest.addSniffer(WebInspector.debuggerModel, "_didEditScriptSource", callback);
sourceFrame._textViewer.readOnly = false;
sourceFrame.startEditing();
var newText = sourceFrame._textModel.text.replace(string, replacement);
sourceFrame._textModel.setText(null, newText);
var oldRange, newRange;
var lines = sourceFrame._textModel._lines;
for (var i = 0; i < lines.length; ++i) {
var column = lines[i].indexOf(string);
if (column === -1)
continue;
lines[i] = lines[i].replace(string, replacement);
var lineEndings = replacement.lineEndings();
var lastLineLength = lineEndings[lineEndings.length - 1] - (lineEndings[lineEndings.length - 2] || 0);
oldRange = new WebInspector.TextRange(i, column, i, column + string.length);
newRange = new WebInspector.TextRange(i, column, i + lineEndings.length - 1, lastLineLength);
break;
}
sourceFrame.endEditing(oldRange, newRange);
sourceFrame._handleSave();
}
};
......
2011-04-07 Pavel Podivilov <podivilov@chromium.org>
Reviewed by Pavel Feldman.
Web Inspector: update breakpoints according to source frame decorations after live edit.
https://bugs.webkit.org/show_bug.cgi?id=58029
* inspector/front-end/DebuggerPresentationModel.js:
(WebInspector.DebuggerPresentationModel.prototype.editScriptSource.didEditScriptSource):
(WebInspector.DebuggerPresentationModel.prototype.editScriptSource):
(WebInspector.DebuggerPresentationModel.prototype._updateResourceContent.didEditScriptSource):
(WebInspector.DebuggerPresentationModel.prototype._updateResourceContent):
* inspector/front-end/SourceFile.js:
(WebInspector.SourceFile.prototype.set content):
* inspector/front-end/SourceFrame.js:
(WebInspector.SourceFrame.prototype._handleSave.didEditScriptSource):
(WebInspector.SourceFrame.prototype._handleSave):
2011-04-08 Pavel Podivilov <podivilov@chromium.org>
 
Reviewed by Pavel Feldman.
......@@ -143,24 +143,34 @@ WebInspector.DebuggerPresentationModel.prototype = {
var oldSource = sourceFile.content;
function didEditScriptSource(error)
{
callback(error);
if (error)
return;
this._updateBreakpointsAfterLiveEdit(sourceFileId, oldSource, newSource);
var resource = WebInspector.resourceForURL(script.sourceURL);
if (resource) {
var revertHandle = this.editScriptSource.bind(this, sourceFileId, oldSource, sourceFile.reload.bind(sourceFile));
resource.setContent(newSource, revertHandle);
if (!error) {
sourceFile.content = newSource;
this._updateResourceContent(sourceFile, oldSource, newSource);
}
if (WebInspector.debuggerModel.callFrames)
callback(error);
if (!error && WebInspector.debuggerModel.callFrames)
this._debuggerPaused();
}
WebInspector.debuggerModel.editScriptSource(script.sourceID, newSource, didEditScriptSource.bind(this));
},
_updateResourceContent: function(sourceFile, oldSource, newSource)
{
var resource = WebInspector.resourceForURL(sourceFile.url);
if (!resource)
return;
function didEditScriptSource(error)
{
this._updateBreakpointsAfterLiveEdit(sourceFile.id, oldSource, newSource);
sourceFile.reload();
}
var revertHandle = this.editScriptSource.bind(this, sourceFile.id, oldSource, didEditScriptSource.bind(this));
resource.setContent(newSource, revertHandle);
},
_updateBreakpointsAfterLiveEdit: function(sourceFileId, oldSource, newSource)
{
var sourceFile = this._sourceFiles[sourceFileId];
......
......@@ -68,6 +68,12 @@ WebInspector.SourceFile.prototype = {
return this._content;
},
set content(content)
{
// FIXME: move live edit implementation to SourceFile and remove this setter.
this._content = content;
},
requestSourceMapping: function(callback)
{
if (!this._mapping)
......
......@@ -225,7 +225,7 @@ WebInspector.SourceFrame.prototype = {
isContentEditable: function()
{
return this._delegate.canEditScriptSource();
return this._delegate.canEditScriptSource() && !this._editScriptSourceInProgress;
},
startEditing: function()
......@@ -902,15 +902,33 @@ WebInspector.SourceFrame.prototype = {
function didEditScriptSource(error)
{
if (error && !this._viewerState && this._textModel.text === newSource) {
this._editScriptSourceInProgress = false;
if (error) {
this._viewerState = originalViewerState;
this._textViewer.readOnly = false;
this._delegate.setScriptSourceIsBeingEdited(true);
WebInspector.log(error.data[0], WebInspector.ConsoleMessage.MessageLevel.Error);
WebInspector.showConsole();
return;
}
var newBreakpoints = {};
for (var lineNumber in this._breakpoints) {
newBreakpoints[lineNumber] = this._breakpoints[lineNumber];
this.removeBreakpoint(Number(lineNumber));
}
for (var lineNumber in originalViewerState.breakpoints)
this._delegate.removeBreakpoint(Number(lineNumber));
for (var lineNumber in newBreakpoints) {
var breakpoint = newBreakpoints[lineNumber];
this._delegate.setBreakpoint(Number(lineNumber), breakpoint.condition, breakpoint.enabled);
}
}
this._delegate.editScriptSource(newSource, didEditScriptSource.bind(this));
this._editScriptSourceInProgress = true;
return true;
},
......
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