@@ -175,14 +175,9 @@ export default class GithubPackage {
175175 return ! ! event . target . closest ( '.github-FilePatchListView' ) . querySelector ( '.is-selected' ) ;
176176 } ;
177177
178- const handleProjectPathsChange = ( ) => {
179- const activeRepository = this . getActiveRepository ( ) ;
180- const activeRepositoryPath = activeRepository ? activeRepository . getWorkingDirectoryPath ( ) : null ;
181- this . scheduleActiveContextUpdate ( { activeRepositoryPath} ) ;
182- } ;
183-
184178 this . subscriptions . add (
185- this . project . onDidChangePaths ( handleProjectPathsChange ) ,
179+ this . project . onDidChangePaths ( this . scheduleActiveContextUpdate ) ,
180+ this . workspace . getCenter ( ) . onDidChangeActivePaneItem ( this . scheduleActiveContextUpdate ) ,
186181 this . styleCalculator . startWatching (
187182 'github-package-styles' ,
188183 [ 'editor.fontSize' , 'editor.fontFamily' , 'editor.lineHeight' , 'editor.tabLength' ] ,
@@ -274,10 +269,6 @@ export default class GithubPackage {
274269 } ) ) ;
275270 }
276271
277- const changeWorkingDirectory = workingDirectory => {
278- this . scheduleActiveContextUpdate ( { activeRepositoryPath : workingDirectory } ) ;
279- } ;
280-
281272 this . renderFn (
282273 < RootController
283274 ref = { c => { this . controller = c ; } }
@@ -303,8 +294,6 @@ export default class GithubPackage {
303294 startOpen = { this . startOpen }
304295 startRevealed = { this . startRevealed }
305296 removeFilePatchItem = { this . removeFilePatchItem }
306- currentWorkDir = { this . getActiveWorkdir ( ) }
307- changeWorkingDirectory = { changeWorkingDirectory }
308297 /> , this . element , callback ,
309298 ) ;
310299 }
@@ -506,13 +495,14 @@ export default class GithubPackage {
506495 * Derive the git working directory context that should be used for the package's git operations based on the current
507496 * state of the Atom workspace. In priority, this prefers:
508497 *
509- * - The preferred git working directory set by the user (This is also the working directory that was active when the
510- * package was last serialized).
511- * - A git working directory corresponding to "first" Project, whether or not there is a single project or multiple.
498+ * - A git working directory that contains the active pane item in the workspace's center.
499+ * - A git working directory corresponding to a single Project.
500+ * - When initially activating the package, the working directory that was active when the package was last
501+ * serialized.
512502 * - The current context, unchanged, which may be a `NullWorkdirContext`.
513503 *
514504 * First updates the pool of resident contexts to match all git working directories that correspond to open
515- * projects.
505+ * projects and pane items .
516506 */
517507 async getNextContext ( savedState ) {
518508 const workdirs = new Set (
@@ -524,34 +514,50 @@ export default class GithubPackage {
524514 ) ,
525515 ) ;
526516
527- // Update pool with the open projects
528- this . contextPool . set ( workdirs , savedState ) ;
517+ const fromPaneItem = async maybeItem => {
518+ const itemPath = pathForPaneItem ( maybeItem ) ;
529519
530- if ( savedState . activeRepositoryPath ) {
531- // Preferred git directory (the preferred directory or the last serialized directory).
532- const stateContext = this . contextPool . getContext ( savedState . activeRepositoryPath ) ;
533- // If the context exists chose it, else continue.
534- if ( stateContext . isPresent ( ) ) {
535- return stateContext ;
520+ if ( ! itemPath ) {
521+ return { } ;
536522 }
537- }
538523
539- const projectPaths = this . project . getPaths ( ) ;
524+ const itemWorkdir = await this . workdirCache . find ( itemPath ) ;
525+
526+ if ( itemWorkdir && ! this . project . contains ( itemPath ) ) {
527+ workdirs . add ( itemWorkdir ) ;
528+ }
529+
530+ return { itemPath, itemWorkdir} ;
531+ } ;
532+
533+ const active = await fromPaneItem ( this . workspace . getCenter ( ) . getActivePaneItem ( ) ) ;
534+
535+ this . contextPool . set ( workdirs , savedState ) ;
540536
541- if ( projectPaths . length >= 1 ) {
542- // Single or multiple projects (just choose the first, the user can select after)
543- const projectPath = projectPaths [ 0 ] ;
537+ if ( active . itemPath ) {
538+ // Prefer an active item
539+ return this . contextPool . getContext ( active . itemWorkdir || active . itemPath ) ;
540+ }
541+
542+ if ( this . project . getPaths ( ) . length === 1 ) {
543+ // Single project
544+ const projectPath = this . project . getPaths ( ) [ 0 ] ;
544545 const activeWorkingDir = await this . workdirCache . find ( projectPath ) ;
545546 return this . contextPool . getContext ( activeWorkingDir || projectPath ) ;
546547 }
547548
548- if ( projectPaths . length === 0 && ! this . activeContext . getRepository ( ) . isUndetermined ( ) ) {
549+ if ( this . project . getPaths ( ) . length === 0 && ! this . activeContext . getRepository ( ) . isUndetermined ( ) ) {
549550 // No projects. Revert to the absent context unless we've guessed that more projects are on the way.
550551 return WorkdirContext . absent ( { pipelineManager : this . pipelineManager } ) ;
551552 }
552553
553- // It is only possible to reach here if there there was no preferred directory, there are no project paths and the
554- // the active context's repository is not undetermined.
554+ // Restore models from saved state. Will return a NullWorkdirContext if this path is not presently
555+ // resident in the pool.
556+ const savedWorkingDir = savedState . activeRepositoryPath ;
557+ if ( savedWorkingDir ) {
558+ return this . contextPool . getContext ( savedWorkingDir ) ;
559+ }
560+
555561 return this . activeContext ;
556562 }
557563
@@ -594,3 +600,22 @@ export default class GithubPackage {
594600 }
595601 }
596602}
603+
604+ function pathForPaneItem ( paneItem ) {
605+ if ( ! paneItem ) {
606+ return null ;
607+ }
608+
609+ // Likely GitHub package provided pane item
610+ if ( typeof paneItem . getWorkingDirectory === 'function' ) {
611+ return paneItem . getWorkingDirectory ( ) ;
612+ }
613+
614+ // TextEditor-like
615+ if ( typeof paneItem . getPath === 'function' ) {
616+ return paneItem . getPath ( ) ;
617+ }
618+
619+ // Oh well
620+ return null ;
621+ }
0 commit comments