Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5fa4cde

Browse files
authored
Merge pull request atom#847 from atom/aw-preserve-context
Choose the active context by the active item in the workspace center
2 parents 110e254 + 9ac1d90 commit 5fa4cde

File tree

4 files changed

+57
-11
lines changed

4 files changed

+57
-11
lines changed

lib/controllers/git-tab-controller.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ export default class GitTabController {
118118
return 'atom-github://stub-uri/git-tab-controller';
119119
}
120120

121+
getWorkingDirectory() {
122+
return this.props.repository.getWorkingDirectoryPath();
123+
}
124+
121125
getLastModelDataRefreshPromise() {
122126
return this.repositoryObserver.getLastModelDataRefreshPromise();
123127
}

lib/controllers/github-tab-controller.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ export default class GithubTabController extends React.Component {
150150
return 'atom-github://stub-uri/github-tab-controller';
151151
}
152152

153+
getWorkingDirectory() {
154+
return this.props.repository.getWorkingDirectoryPath();
155+
}
156+
153157
renderNoRemotes() {
154158
return (
155159
<div className="github-GithubTabController-no-remotes">

lib/github-package.js

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,8 @@ export default class GithubPackage {
313313
* Derive the git working directory context that should be used for the package's git operations based on the current
314314
* state of the Atom workspace. In priority, this prefers:
315315
*
316-
* - A git working directory that contains the active pane item.
316+
* - A git working directory that contains the workspace's active pane item.
317+
* - A git working directory that contains the pane item in the workspace's center.
317318
* - A git working directory corresponding to a single Project.
318319
* - When initially activating the package, the working directory that was active when the package was last
319320
* serialized.
@@ -332,21 +333,38 @@ export default class GithubPackage {
332333
),
333334
);
334335

335-
const activeItemPath = pathForPaneItem(this.workspace.getActivePaneItem());
336-
let activeItemWorkdir = null;
337-
if (activeItemPath) {
338-
activeItemWorkdir = await this.workdirCache.find(activeItemPath);
339-
}
336+
const fromPaneItem = async maybeItem => {
337+
const itemPath = pathForPaneItem(maybeItem);
340338

341-
if (activeItemWorkdir && !this.project.contains(activeItemPath)) {
342-
workdirs.add(activeItemWorkdir);
343-
}
339+
if (!itemPath) {
340+
return {};
341+
}
342+
343+
const itemWorkdir = await this.workdirCache.find(itemPath);
344+
345+
if (itemWorkdir && !this.project.contains(itemPath)) {
346+
workdirs.add(itemWorkdir);
347+
}
348+
349+
return {itemPath, itemWorkdir};
350+
};
351+
352+
const items = [
353+
this.workspace.getActivePaneItem(),
354+
this.workspace.getCenter && this.workspace.getCenter().getActivePaneItem(),
355+
];
356+
const [active, center = {}] = await Promise.all(items.map(fromPaneItem));
344357

345358
this.contextPool.set(workdirs, savedState);
346359

347-
if (activeItemPath) {
360+
if (active.itemPath) {
348361
// Prefer an active item
349-
return this.contextPool.getContext(activeItemWorkdir || activeItemPath);
362+
return this.contextPool.getContext(active.itemWorkdir || active.itemPath);
363+
}
364+
365+
if (center.itemPath) {
366+
// Try the item active in the Workspace's center
367+
return this.contextPool.getContext(center.itemWorkdir || center.itemPath);
350368
}
351369

352370
if (this.project.getPaths().length === 1) {

test/github-package.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,26 @@ describe('GithubPackage', function() {
431431
assert.isTrue(githubPackage.getActiveRepository().isAbsent());
432432
});
433433

434+
it('uses the context of the PaneItem active in the workspace center', async function() {
435+
if (!workspace.getLeftDock) {
436+
this.skip();
437+
}
438+
439+
const [workdir0, workdir1] = await Promise.all([
440+
cloneRepository('three-files'),
441+
cloneRepository('three-files'),
442+
]);
443+
project.setPaths([workdir1]);
444+
445+
await workspace.open(path.join(workdir0, 'a.txt'));
446+
commandRegistry.dispatch(atomEnv.views.getView(workspace), 'tree-view:toggle-focus');
447+
workspace.getLeftDock().activate();
448+
449+
await githubPackage.scheduleActiveContextUpdate();
450+
451+
assert.equal(githubPackage.getActiveWorkdir(), workdir0);
452+
});
453+
434454
it('uses the context of a single open project', async function() {
435455
const [workdirPath1, workdirPath2] = await Promise.all([
436456
cloneRepository('three-files'),

0 commit comments

Comments
 (0)