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

DevTools: keep selected tab as persistence binding comes in

This patch fixes a bug in the TabbedEditorContainer's handler for
persistence binding.

As the binding comes in, we should retain selected tab no matter
what.

R=dgozman

Review-Url: https://codereview.chromium.org/2740053002
Cr-Commit-Position: refs/heads/master@{#456162}
parent e2a3dd0d
...@@ -409,7 +409,7 @@ InspectorTest.dumpNavigatorViewInMode = function(view, mode) ...@@ -409,7 +409,7 @@ InspectorTest.dumpNavigatorViewInMode = function(view, mode)
InspectorTest.dumpNavigatorView(view); InspectorTest.dumpNavigatorView(view);
} }
InspectorTest.waitForUISourceCode = function(url, projectType) InspectorTest.waitForUISourceCode = function(urlSuffix, projectType)
{ {
function matches(uiSourceCode) function matches(uiSourceCode)
{ {
...@@ -417,13 +417,13 @@ InspectorTest.waitForUISourceCode = function(url, projectType) ...@@ -417,13 +417,13 @@ InspectorTest.waitForUISourceCode = function(url, projectType)
return false; return false;
if (!projectType && uiSourceCode.project().type() === Workspace.projectTypes.Service) if (!projectType && uiSourceCode.project().type() === Workspace.projectTypes.Service)
return false; return false;
if (url && !uiSourceCode.url().endsWith(url)) if (urlSuffix && !uiSourceCode.url().endsWith(urlSuffix))
return false; return false;
return true; return true;
} }
for (var uiSourceCode of Workspace.workspace.uiSourceCodes()) { for (var uiSourceCode of Workspace.workspace.uiSourceCodes()) {
if (url && matches(uiSourceCode)) if (urlSuffix && matches(uiSourceCode))
return Promise.resolve(uiSourceCode); return Promise.resolve(uiSourceCode);
} }
......
...@@ -28,6 +28,10 @@ InspectorTest.TestFileSystem.prototype = { ...@@ -28,6 +28,10 @@ InspectorTest.TestFileSystem.prototype = {
} }
}, },
reportCreatedPromise: function() {
return new Promise(fulfill => this.reportCreated(fulfill));
},
reportCreated: function(callback) reportCreated: function(callback)
{ {
var fileSystemPath = this.fileSystemPath; var fileSystemPath = this.fileSystemPath;
......
...@@ -11,8 +11,8 @@ SourceFrame: http://127.0.0.1:8000/inspector/persistence/resources/foo.js ...@@ -11,8 +11,8 @@ SourceFrame: http://127.0.0.1:8000/inspector/persistence/resources/foo.js
Running: openFileSystemTab Running: openFileSystemTab
SourceFrame: file:///var/www/inspector/persistence/resources/foo.js SourceFrame: file:///var/www/inspector/persistence/resources/foo.js
selection: {"startLine":0,"startColumn":0,"endLine":0,"endColumn":0} selection: {"startLine":1,"startColumn":0,"endLine":2,"endColumn":5}
firstVisibleLine: 0 firstVisibleLine: 1
isDirty: false isDirty: false
Opened tabs: Opened tabs:
file:///var/www/inspector/persistence/resources/foo.js file:///var/www/inspector/persistence/resources/foo.js
...@@ -22,15 +22,15 @@ Running: addFileMapping ...@@ -22,15 +22,15 @@ Running: addFileMapping
Opened tabs: Opened tabs:
file:///var/www/inspector/persistence/resources/foo.js file:///var/www/inspector/persistence/resources/foo.js
SourceFrame: file:///var/www/inspector/persistence/resources/foo.js SourceFrame: file:///var/www/inspector/persistence/resources/foo.js
selection: {"startLine":2,"startColumn":0,"endLine":2,"endColumn":5} selection: {"startLine":1,"startColumn":0,"endLine":2,"endColumn":5}
firstVisibleLine: 2 firstVisibleLine: 1
isDirty: false isDirty: false
Running: removeFileMapping Running: removeFileMapping
Opened tabs: Opened tabs:
file:///var/www/inspector/persistence/resources/foo.js file:///var/www/inspector/persistence/resources/foo.js
SourceFrame: file:///var/www/inspector/persistence/resources/foo.js SourceFrame: file:///var/www/inspector/persistence/resources/foo.js
selection: {"startLine":2,"startColumn":0,"endLine":2,"endColumn":5} selection: {"startLine":1,"startColumn":0,"endLine":2,"endColumn":5}
firstVisibleLine: 2 firstVisibleLine: 1
isDirty: false isDirty: false
...@@ -44,6 +44,8 @@ function test() ...@@ -44,6 +44,8 @@ function test()
function onFileSystemTab(sourceFrame) function onFileSystemTab(sourceFrame)
{ {
fileSystemSourceFrame = sourceFrame; fileSystemSourceFrame = sourceFrame;
fileSystemSourceFrame.setSelection(new Common.TextRange(1, 0, 2, 5));
fileSystemSourceFrame.scrollToLine(1);
dumpSourceFrame(fileSystemSourceFrame); dumpSourceFrame(fileSystemSourceFrame);
dumpEditorTabs(); dumpEditorTabs();
next(); next();
......
Verify that tab keeps selected as the persistence binding comes in.
Opened tabs before persistence binding:
1: bar.js
2: foo.js
3: foo.js [selected]
Opened tabs after persistence binding:
1: bar.js
2: foo.js [selected]
<html>
<head>
<script src='../inspector-test.js'></script>
<script src='../debugger-test.js'></script>
<script src='../isolated-filesystem-test.js'></script>
<script src='./persistence-test.js'></script>
<script src='./resources/foo.js'></script>
<script>
async function test()
{
var fs = new InspectorTest.TestFileSystem('file:///var/www');
var fsEntry = InspectorTest.addFooJSFile(fs);
fs.root.addFile('bar.js', "window.bar = ()=>'bar';");
await fs.reportCreatedPromise();
var fsSourceCode = await InspectorTest.waitForUISourceCode('foo.js', Workspace.projectTypes.FileSystem);
var networkSourceCode = await InspectorTest.waitForUISourceCode('foo.js', Workspace.projectTypes.Network);
var barSourceCode = await InspectorTest.waitForUISourceCode('bar.js');
UI.panels.sources.showUISourceCode(barSourceCode, 0, 0);
UI.panels.sources.showUISourceCode(networkSourceCode, 0, 0);
// Open and select file system tab. Selection should stay here.
UI.panels.sources.showUISourceCode(fsSourceCode, 0, 0);
dumpTabs('Opened tabs before persistence binding:');
Workspace.fileSystemMapping.addFileMapping(fs.fileSystemPath, 'http://127.0.0.1:8000', '/');
await InspectorTest.waitForBinding('foo.js');
dumpTabs('\nOpened tabs after persistence binding:');
InspectorTest.completeTest();
function dumpTabs(title)
{
var tabbedPane = UI.panels.sources._sourcesView._editorContainer._tabbedPane;
var tabs = tabbedPane._tabs;
InspectorTest.addResult(title);
for (var i = 0; i < tabs.length; ++i) {
var text = (i + 1) + ': ';
text += tabs[i].title;
if (tabs[i] === tabbedPane._currentTab)
text += ' [selected]';
InspectorTest.addResult(' ' + text);
}
}
};
</script>
</head>
<body onload='runTest()'>
<p>Verify that tab keeps selected as the persistence binding comes in.</p>
</body>
</html>
...@@ -91,19 +91,18 @@ Sources.TabbedEditorContainer = class extends Common.Object { ...@@ -91,19 +91,18 @@ Sources.TabbedEditorContainer = class extends Common.Object {
if (!networkTabId) if (!networkTabId)
return; return;
var tabIndex = this._tabbedPane.tabIndex(networkTabId); if (!fileSystemTabId) {
var tabsToClose = [networkTabId]; var tabIndex = this._tabbedPane.tabIndex(networkTabId);
if (fileSystemTabId) fileSystemTabId = this._appendFileTab(binding.fileSystem, false, tabIndex);
tabsToClose.push(fileSystemTabId); var fileSystemTabView = /** @type {!UI.Widget} */ (this._tabbedPane.tabView(fileSystemTabId));
this._closeTabs(tabsToClose, true); this._restoreEditorProperties(fileSystemTabView, currentSelectionRange, currentScrollLineNumber);
fileSystemTabId = this._appendFileTab(binding.fileSystem, false, tabIndex); }
this._updateHistory();
this._closeTabs([networkTabId], true);
if (wasSelectedInNetwork) if (wasSelectedInNetwork)
this._tabbedPane.selectTab(fileSystemTabId, false); this._tabbedPane.selectTab(fileSystemTabId, false);
var fileSystemTabView = /** @type {!UI.Widget} */ (this._tabbedPane.tabView(fileSystemTabId)); this._updateHistory();
this._restoreEditorProperties(fileSystemTabView, currentSelectionRange, currentScrollLineNumber);
} }
/** /**
......
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