Commit d70e6764 authored by lushnikov's avatar lushnikov Committed by Commit bot

DevTools: restore selection and scrollposition between network and filesystem

BUG=658089
R=dgozman

Review-Url: https://codereview.chromium.org/2435043003
Cr-Commit-Position: refs/heads/master@{#427268}
parent fd61ca3f
......@@ -3,7 +3,17 @@ Verify that tabs get merged and split when binding is added and removed.
Running: addFileSystem
Running: openEditorTabs
Running: openNetworkTab
SourceFrame: http://127.0.0.1:8000/inspector/persistence/resources/foo.js
selection: {"startLine":0,"startColumn":0,"endLine":0,"endColumn":0}
firstVisibleLine: 0
isDirty: false
Running: openFileSystemTab
SourceFrame: file:///var/www/inspector/persistence/resources/foo.js
selection: {"startLine":2,"startColumn":0,"endLine":2,"endColumn":5}
firstVisibleLine: 2
isDirty: true
Opened tabs:
file:///var/www/inspector/persistence/resources/foo.js
http://127.0.0.1:8000/inspector/persistence/resources/foo.js
......@@ -11,9 +21,17 @@ Opened tabs:
Running: addFileMapping
Opened tabs:
http://127.0.0.1:8000/inspector/persistence/resources/foo.js
SourceFrame: http://127.0.0.1:8000/inspector/persistence/resources/foo.js
selection: {"startLine":2,"startColumn":0,"endLine":2,"endColumn":5}
firstVisibleLine: 2
isDirty: true
Running: removeFileMapping
Opened tabs:
file:///var/www/inspector/persistence/resources/foo.js
http://127.0.0.1:8000/inspector/persistence/resources/foo.js
SourceFrame: http://127.0.0.1:8000/inspector/persistence/resources/foo.js
selection: {"startLine":2,"startColumn":0,"endLine":2,"endColumn":5}
firstVisibleLine: 2
isDirty: true
......@@ -12,6 +12,7 @@ function test()
{
var fs = new InspectorTest.TestFileSystem("file:///var/www");
var fsEntry = InspectorTest.addFooJSFile(fs);
var networkSourceFrame, fileSystemSourceFrame;
InspectorTest.runTestSuite([
function addFileSystem(next)
......@@ -19,18 +20,38 @@ function test()
fs.reportCreated(next);
},
function openEditorTabs(next)
function openNetworkTab(next)
{
var promises = [
InspectorTest.waitForUISourceCode("foo.js", WebInspector.projectTypes.Network)
.then(code => InspectorTest.showUISourceCode(code)),
InspectorTest.waitForUISourceCode("foo.js", WebInspector.projectTypes.FileSystem)
.then(code => InspectorTest.showUISourceCode(code))
];
Promise.all(promises).then(onTabsOpened);
InspectorTest.waitForUISourceCode("foo.js", WebInspector.projectTypes.Network)
.then(code => InspectorTest.showUISourceCodePromise(code))
.then(onNetworkTab);
function onTabsOpened()
function onNetworkTab(sourceFrame)
{
networkSourceFrame = sourceFrame;
dumpSourceFrame(networkSourceFrame);
next();
}
},
function openFileSystemTab(next)
{
InspectorTest.waitForUISourceCode("foo.js", WebInspector.projectTypes.FileSystem)
.then(onFileSystemSourceCode)
.then(onFileSystemTab);
function onFileSystemSourceCode(code)
{
code.setWorkingCopy("\n\nwindow.foo = ()=>'foo2';");
return InspectorTest.showUISourceCodePromise(code);
}
function onFileSystemTab(sourceFrame)
{
fileSystemSourceFrame = sourceFrame;
fileSystemSourceFrame.setSelection(new WebInspector.TextRange(2, 0, 2, 5));
fileSystemSourceFrame.scrollToLine(2);
dumpSourceFrame(fileSystemSourceFrame);
dumpEditorTabs();
next();
}
......@@ -41,9 +62,10 @@ function test()
InspectorTest.waitForBinding("foo.js").then(onBindingCreated);
WebInspector.fileSystemMapping.addFileMapping(fs.fileSystemPath, "http://127.0.0.1:8000", "/");
function onBindingCreated(binding)
function onBindingCreated()
{
dumpEditorTabs();
dumpSourceFrame(networkSourceFrame);
next();
}
},
......@@ -60,6 +82,7 @@ function test()
return
WebInspector.persistence.removeEventListener(WebInspector.Persistence.Events.BindingRemoved, onBindingRemoved);
dumpEditorTabs();
dumpSourceFrame(networkSourceFrame);
next();
}
},
......@@ -74,6 +97,14 @@ function test()
for (code of openedUISourceCodes)
InspectorTest.addResult(" " + code.url());
}
function dumpSourceFrame(sourceFrame)
{
InspectorTest.addResult("SourceFrame: " + sourceFrame._url);
InspectorTest.addResult(" selection: " + sourceFrame.selection());
InspectorTest.addResult(" firstVisibleLine: " + sourceFrame.textEditor.firstVisibleLine());
InspectorTest.addResult(" isDirty: " + sourceFrame.uiSourceCode().isDirty());
}
};
</script>
</head>
......
......@@ -5,13 +5,13 @@ Running: waitForUISourceCodes
Running: dumpSearchResults
Search result #1: uiSourceCode.url = file:///var/www/inspector/persistence/resources/foo.js
search match #1: lineNumber = 0, lineContent = 'window.foo = ()=>'foo';'
search match #1: lineNumber = 2, lineContent = 'window.foo = ()=>'foo';'
Search result #2: uiSourceCode.url = http://127.0.0.1:8000/inspector/persistence/resources/foo.js
search match #1: lineNumber = 0, lineContent = 'window.foo = ()=>'foo';'
search match #1: lineNumber = 2, lineContent = 'window.foo = ()=>'foo';'
Running: addFileMapping
Running: dumpSearchResults
Search result #1: uiSourceCode.url = http://127.0.0.1:8000/inspector/persistence/resources/foo.js
search match #1: lineNumber = 0, lineContent = 'window.foo = ()=>'foo';'
search match #1: lineNumber = 2, lineContent = 'window.foo = ()=>'foo';'
......@@ -68,7 +68,7 @@ InspectorTest.waitForUISourceCode = function(name, projectType)
InspectorTest.addFooJSFile = function(fs)
{
return fs.root.mkdir("inspector").mkdir("persistence").mkdir("resources").addFile("foo.js", "window.foo = ()=>'foo';");
return fs.root.mkdir("inspector").mkdir("persistence").mkdir("resources").addFile("foo.js", "\n\nwindow.foo = ()=>'foo';");
}
}
......@@ -38,10 +38,13 @@ WebInspector.Persistence.prototype = {
*/
_onBindingCreated: function(binding)
{
if (binding.network.isDirty() || binding.fileSystem.isDirty()) {
if (binding.network.isDirty()) {
WebInspector.console.log(WebInspector.UIString("%s can not be persisted to file system due to unsaved changes.", binding.network.name()));
return;
}
if (binding.fileSystem.isDirty())
binding.network.setWorkingCopy(binding.fileSystem.workingCopy());
binding.network[WebInspector.Persistence._binding] = binding;
binding.fileSystem[WebInspector.Persistence._binding] = binding;
......@@ -61,6 +64,9 @@ WebInspector.Persistence.prototype = {
*/
_onBindingRemoved: function(binding)
{
if (binding.network.isDirty())
binding.fileSystem.setWorkingCopy(binding.network.workingCopy());
binding.network[WebInspector.Persistence._binding] = null;
binding.fileSystem[WebInspector.Persistence._binding] = null;
......
......@@ -67,6 +67,16 @@ WebInspector.SourcesTextEditor.prototype = {
return !!this._tokenHighlighter.highlightedRegex();
},
/**
* @override
* @param {number} lineNumber
*/
scrollToLine: function(lineNumber)
{
WebInspector.CodeMirrorTextEditor.prototype.scrollToLine.call(this, lineNumber);
this._scroll();
},
/**
* @param {!RegExp} regex
* @param {?WebInspector.TextRange} range
......
......@@ -95,13 +95,22 @@ WebInspector.TabbedEditorContainer.prototype = {
this._tabbedPane.changeTabTitle(networkTabId, this._titleForFile(binding.fileSystem), this._tooltipForFile(binding.fileSystem));
if (!fileSystemTabId)
return;
var wasSelectedInFileSystem = this._currentFile === binding.fileSystem;
var currentSelectionRange = this._history.selectionRange(binding.fileSystem.url());
var currentScrollLineNumber = this._history.scrollLineNumber(binding.fileSystem.url());
var tabIndex = this._tabbedPane.tabIndex(fileSystemTabId);
this._closeTabs([fileSystemTabId]);
this._closeTabs([fileSystemTabId], true);
if (!networkTabId)
networkTabId = this._appendFileTab(binding.network, false, tabIndex);
this._updateHistory();
if (wasSelectedInFileSystem)
this._tabbedPane.selectTab(networkTabId, false);
var networkTabView = /** @type {!WebInspector.Widget} */(this._tabbedPane.tabView(networkTabId));
this._restoreEditorProperties(networkTabView, currentSelectionRange, currentScrollLineNumber);
},
/**
......@@ -113,7 +122,14 @@ WebInspector.TabbedEditorContainer.prototype = {
var networkTabId = this._tabIds.get(binding.network);
if (!networkTabId)
return;
this._appendFileTab(binding.fileSystem, false);
var fileSystemTabId = this._appendFileTab(binding.fileSystem, false);
this._updateHistory();
var fileSystemTabView = /** @type {!WebInspector.Widget} */(this._tabbedPane.tabView(fileSystemTabId));
var savedSelectionRange = this._history.selectionRange(binding.network.url());
var savedScrollLineNumber = this._history.scrollLineNumber(binding.network.url());
this._restoreEditorProperties(fileSystemTabView, savedSelectionRange, savedScrollLineNumber);
},
/**
......@@ -234,16 +250,14 @@ WebInspector.TabbedEditorContainer.prototype = {
if (this._scrollTimer)
clearTimeout(this._scrollTimer);
var lineNumber = /** @type {number} */ (event.data);
this._scrollTimer = setTimeout(updateHistory.bind(this, this._currentFile.url(), lineNumber), 100);
this._scrollTimer = setTimeout(saveHistory.bind(this), 100);
this._history.updateScrollLineNumber(this._currentFile.url(), lineNumber);
/**
* @param {string} url
* @param {number} lineNumber
* @this {WebInspector.TabbedEditorContainer}
*/
function updateHistory(url, lineNumber)
function saveHistory()
{
this._history.updateScrollLineNumber(url, lineNumber);
this._history.save(this._previouslyViewedFilesSetting);
}
},
......@@ -327,15 +341,16 @@ WebInspector.TabbedEditorContainer.prototype = {
/**
* @param {!Array.<string>} ids
* @param {boolean=} forceCloseDirtyTabs
*/
_closeTabs: function(ids)
_closeTabs: function(ids, forceCloseDirtyTabs)
{
var dirtyTabs = [];
var cleanTabs = [];
for (var i = 0; i < ids.length; ++i) {
var id = ids[i];
var uiSourceCode = this._files[id];
if (uiSourceCode.isDirty())
if (!forceCloseDirtyTabs && uiSourceCode.isDirty())
dirtyTabs.push(id);
else
cleanTabs.push(id);
......@@ -462,7 +477,6 @@ WebInspector.TabbedEditorContainer.prototype = {
_appendFileTab: function(uiSourceCode, userGesture, index)
{
var view = this._delegate.viewForFile(uiSourceCode);
var sourceFrame = view instanceof WebInspector.SourceFrame ? /** @type {!WebInspector.SourceFrame} */ (view) : null;
var title = this._titleForFile(uiSourceCode);
var tooltip = this._tooltipForFile(uiSourceCode);
......@@ -471,11 +485,8 @@ WebInspector.TabbedEditorContainer.prototype = {
this._files[tabId] = uiSourceCode;
var savedSelectionRange = this._history.selectionRange(uiSourceCode.url());
if (sourceFrame && savedSelectionRange)
sourceFrame.setSelection(savedSelectionRange);
var savedScrollLineNumber = this._history.scrollLineNumber(uiSourceCode.url());
if (sourceFrame && savedScrollLineNumber)
sourceFrame.scrollToLine(savedScrollLineNumber);
this._restoreEditorProperties(view, savedSelectionRange, savedScrollLineNumber);
this._tabbedPane.appendTab(tabId, title, view, tooltip, userGesture, undefined, index);
......@@ -484,6 +495,22 @@ WebInspector.TabbedEditorContainer.prototype = {
return tabId;
},
/**
* @param {!WebInspector.Widget} editorView
* @param {!WebInspector.TextRange=} selection
* @param {number=} firstLineNumber
*/
_restoreEditorProperties: function(editorView, selection, firstLineNumber)
{
var sourceFrame = editorView instanceof WebInspector.SourceFrame ? /** @type {!WebInspector.SourceFrame} */ (editorView) : null;
if (!sourceFrame)
return;
if (selection)
sourceFrame.setSelection(selection);
if (typeof firstLineNumber === "number")
sourceFrame.scrollToLine(firstLineNumber);
},
/**
* @param {!WebInspector.Event} event
*/
......
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