summaryrefslogtreecommitdiffstats
path: root/WebCore/inspector/front-end/SourceView.js
diff options
context:
space:
mode:
authorBen Murdoch <benm@google.com>2010-05-11 18:35:50 +0100
committerBen Murdoch <benm@google.com>2010-05-14 10:23:05 +0100
commit21939df44de1705786c545cd1bf519d47250322d (patch)
treeef56c310f5c0cdc379c2abb2e212308a3281ce20 /WebCore/inspector/front-end/SourceView.js
parent4ff1d8891d520763f17675827154340c7c740f90 (diff)
downloadexternal_webkit-21939df44de1705786c545cd1bf519d47250322d.zip
external_webkit-21939df44de1705786c545cd1bf519d47250322d.tar.gz
external_webkit-21939df44de1705786c545cd1bf519d47250322d.tar.bz2
Merge Webkit at r58956: Initial merge by Git.
Change-Id: I1d9fb60ea2c3f2ddc04c17a871acdb39353be228
Diffstat (limited to 'WebCore/inspector/front-end/SourceView.js')
-rw-r--r--WebCore/inspector/front-end/SourceView.js55
1 files changed, 43 insertions, 12 deletions
diff --git a/WebCore/inspector/front-end/SourceView.js b/WebCore/inspector/front-end/SourceView.js
index 9fbd161..3621187 100644
--- a/WebCore/inspector/front-end/SourceView.js
+++ b/WebCore/inspector/front-end/SourceView.js
@@ -32,7 +32,8 @@ WebInspector.SourceView = function(resource)
this.element.addStyleClass("source");
- this.sourceFrame = new WebInspector.SourceFrame(this.contentElement, this._addBreakpoint.bind(this), this._removeBreakpoint.bind(this));
+ var canEditScripts = WebInspector.panels.scripts.canEditScripts() && resource.type === WebInspector.Resource.Type.Script;
+ this.sourceFrame = new WebInspector.SourceFrame(this.contentElement, this._addBreakpoint.bind(this), this._removeBreakpoint.bind(this), canEditScripts ? this._editLine.bind(this) : null);
resource.addEventListener("finished", this._resourceLoadingFinished, this);
this._frameNeedsSetup = true;
}
@@ -77,6 +78,11 @@ WebInspector.SourceView.prototype = {
WebInspector.getResourceContent(this.resource.identifier, this._contentLoaded.bind(this));
},
+ hasContentTab: function()
+ {
+ return true;
+ },
+
contentTabSelected: function()
{
this.setupSourceFrameIfNeeded();
@@ -105,17 +111,7 @@ WebInspector.SourceView.prototype = {
_addBreakpoint: function(line)
{
- var sourceID = null;
- var closestStartingLine = 0;
- var scripts = this.resource.scripts;
- for (var i = 0; i < scripts.length; ++i) {
- var script = scripts[i];
- if (script.startingLine <= line && script.startingLine >= closestStartingLine) {
- closestStartingLine = script.startingLine;
- sourceID = script.sourceID;
- }
- }
-
+ var sourceID = this._sourceIDForLine(line);
if (WebInspector.panels.scripts) {
var breakpoint = new WebInspector.Breakpoint(this.resource.url, line, sourceID);
WebInspector.panels.scripts.addBreakpoint(breakpoint);
@@ -128,6 +124,41 @@ WebInspector.SourceView.prototype = {
WebInspector.panels.scripts.removeBreakpoint(breakpoint);
},
+ _editLine: function(line, newContent)
+ {
+ var lines = [];
+ var textModel = this.sourceFrame.textModel;
+ for (var i = 0; i < textModel.linesCount; ++i) {
+ if (i === line)
+ lines.push(newContent);
+ else
+ lines.push(textModel.line(i));
+ }
+
+ var linesCountToShift = newContent.split("\n").length - 1;
+ WebInspector.panels.scripts.editScriptSource(this._sourceIDForLine(line), lines.join("\n"), line, linesCountToShift, this._editLineComplete.bind(this));
+ },
+
+ _editLineComplete: function(newBody)
+ {
+ this.sourceFrame.updateContent(newBody);
+ },
+
+ _sourceIDForLine: function(line)
+ {
+ var sourceID = null;
+ var closestStartingLine = 0;
+ var scripts = this.resource.scripts;
+ for (var i = 0; i < scripts.length; ++i) {
+ var script = scripts[i];
+ if (script.startingLine <= line && script.startingLine >= closestStartingLine) {
+ closestStartingLine = script.startingLine;
+ sourceID = script.sourceID;
+ }
+ }
+ return sourceID;
+ },
+
// The rest of the methods in this prototype need to be generic enough to work with a ScriptView.
// The ScriptView prototype pulls these methods into it's prototype to avoid duplicate code.