diff --git a/src/trackers/gitLineTracker.ts b/src/trackers/gitLineTracker.ts index d7319c7..5dd6b3a 100644 --- a/src/trackers/gitLineTracker.ts +++ b/src/trackers/gitLineTracker.ts @@ -74,8 +74,12 @@ export class GitLineTracker extends LineTracker { return this._subscriptions.has(subscriber); } - start(subscriber: any, subscription: Disposable): void { - if (this.isSubscribed(subscriber)) return; + start(subscriber: any, subscription: Disposable): Disposable { + const disposable = { + dispose: () => this.stop(subscriber) + }; + + if (this.isSubscribed(subscriber)) return disposable; this._subscriptions.set(subscriber, subscription); @@ -90,6 +94,8 @@ export class GitLineTracker extends LineTracker { Container.tracker.onDidTriggerDirtyIdle(this.onDirtyIdleTriggered, this) ); } + + return disposable; } stop(subscriber: any) { diff --git a/src/views/explorer.ts b/src/views/explorer.ts index cb393db..a3f7e99 100644 --- a/src/views/explorer.ts +++ b/src/views/explorer.ts @@ -22,14 +22,9 @@ import { isPageable } from './nodes/explorerNode'; import { ResultsExplorer } from './resultsExplorer'; export enum RefreshReason { - ActiveEditorChanged = 'active-editor-changed', - AutoRefreshChanged = 'auto-refresh-changed', - Command = 'command', - ConfigurationChanged = 'configuration', - NodeCommand = 'node-command', - RepoChanged = 'repo-changed', - ViewChanged = 'view-changed', - VisibleEditorsChanged = 'visible-editors-changed' + Command = 'Command', + ConfigurationChanged = 'ConfigurationChanged', + VisibilityChanged = 'VisibilityChanged' } export type Explorer = GitExplorer | FileHistoryExplorer | LineHistoryExplorer | ResultsExplorer; @@ -139,7 +134,8 @@ export abstract class ExplorerBase implements TreeDa } } - await node.refresh(); + const cancel = await node.refresh(); + if (cancel === true) return; this.triggerNodeUpdate(node); } diff --git a/src/views/fileHistoryExplorer.ts b/src/views/fileHistoryExplorer.ts index 0ab7582..1a43273 100644 --- a/src/views/fileHistoryExplorer.ts +++ b/src/views/fileHistoryExplorer.ts @@ -5,15 +5,15 @@ import { CommandContext, setCommandContext } from '../constants'; import { Container } from '../container'; import { ExplorerBase, RefreshReason } from './explorer'; import { RefreshNodeCommandArgs } from './explorerCommands'; -import { ActiveFileHistoryNode, ExplorerNode } from './nodes'; +import { ExplorerNode, FileHistoryTrackerNode } from './nodes'; -export class FileHistoryExplorer extends ExplorerBase { +export class FileHistoryExplorer extends ExplorerBase { constructor() { super('gitlens.fileHistoryExplorer'); } getRoot() { - return new ActiveFileHistoryNode(this); + return new FileHistoryTrackerNode(this); } protected registerCommands() { diff --git a/src/views/lineHistoryExplorer.ts b/src/views/lineHistoryExplorer.ts index 7716906..7d05ab7 100644 --- a/src/views/lineHistoryExplorer.ts +++ b/src/views/lineHistoryExplorer.ts @@ -5,16 +5,15 @@ import { CommandContext, setCommandContext } from '../constants'; import { Container } from '../container'; import { ExplorerBase, RefreshReason } from './explorer'; import { RefreshNodeCommandArgs } from './explorerCommands'; -import { ExplorerNode } from './nodes'; -import { ActiveLineHistoryNode } from './nodes/activeLineHistoryNode'; +import { ExplorerNode, LineHistoryTrackerNode } from './nodes'; -export class LineHistoryExplorer extends ExplorerBase { +export class LineHistoryExplorer extends ExplorerBase { constructor() { super('gitlens.lineHistoryExplorer'); } getRoot() { - return new ActiveLineHistoryNode(this); + return new LineHistoryTrackerNode(this); } protected registerCommands() { diff --git a/src/views/nodes.ts b/src/views/nodes.ts index 963e41d..6981483 100644 --- a/src/views/nodes.ts +++ b/src/views/nodes.ts @@ -1,14 +1,14 @@ 'use strict'; export * from './nodes/explorerNode'; -export * from './nodes/activeFileHistoryNode'; -export * from './nodes/activeLineHistoryNode'; export * from './nodes/branchesNode'; export * from './nodes/branchNode'; export * from './nodes/commitFileNode'; export * from './nodes/commitNode'; export * from './nodes/fileHistoryNode'; -export * from './nodes/activeFileHistoryNode'; +export * from './nodes/fileHistoryTrackerNode'; +export * from './nodes/lineHistoryNode'; +export * from './nodes/lineHistoryTrackerNode'; export * from './nodes/remoteNode'; export * from './nodes/remotesNode'; export * from './nodes/repositoriesNode'; diff --git a/src/views/nodes/explorerNode.ts b/src/views/nodes/explorerNode.ts index 47dfb55..d098c07 100644 --- a/src/views/nodes/explorerNode.ts +++ b/src/views/nodes/explorerNode.ts @@ -65,7 +65,7 @@ export abstract class ExplorerNode { return undefined; } - refresh(): void | Promise {} + refresh(): void | boolean | Promise | Promise {} } export abstract class ExplorerRefNode extends ExplorerNode { diff --git a/src/views/nodes/activeFileHistoryNode.ts b/src/views/nodes/fileHistoryTrackerNode.ts similarity index 92% rename from src/views/nodes/activeFileHistoryNode.ts rename to src/views/nodes/fileHistoryTrackerNode.ts index 0a9b8b5..db9fda3 100644 --- a/src/views/nodes/activeFileHistoryNode.ts +++ b/src/views/nodes/fileHistoryTrackerNode.ts @@ -10,7 +10,7 @@ import { MessageNode } from './common'; import { ExplorerNode, ResourceType, SubscribeableExplorerNode, unknownGitUri } from './explorerNode'; import { FileHistoryNode } from './fileHistoryNode'; -export class ActiveFileHistoryNode extends SubscribeableExplorerNode { +export class FileHistoryTrackerNode extends SubscribeableExplorerNode { private _child: FileHistoryNode | undefined; constructor(explorer: FileHistoryExplorer) { @@ -59,16 +59,18 @@ export class ActiveFileHistoryNode extends SubscribeableExplorerNode e.document && UriComparer.equals(e.document.uri, this.uri))) ) { - return; + return true; } this._uri = unknownGitUri; this.resetChild(); - return; + return false; } - if (UriComparer.equals(editor!.document.uri, this.uri)) return; + if (UriComparer.equals(editor!.document.uri, this.uri)) { + return true; + } let gitUri = await GitUri.fromUri(editor!.document.uri); @@ -86,7 +88,9 @@ export class ActiveFileHistoryNode extends SubscribeableExplorerNode { +export class LineHistoryTrackerNode extends SubscribeableExplorerNode { private _child: LineHistoryNode | undefined; private _selection: Selection | undefined; @@ -67,21 +60,21 @@ export class ActiveLineHistoryNode extends SubscribeableExplorerNode e.document && UriComparer.equals(e.document.uri, this.uri))) ) { - return; + return true; } this._uri = unknownGitUri; this._selection = undefined; this.resetChild(); - return; + return false; } if ( UriComparer.equals(editor!.document.uri, this.uri) && (this._selection !== undefined && editor.selection.isEqual(this._selection)) ) { - return; + return true; } const gitUri = await GitUri.fromUri(editor!.document.uri); @@ -91,26 +84,34 @@ export class ActiveLineHistoryNode extends SubscribeableExplorerNode { + if (e.pending) return; + + onActiveLinesChanged(e); + }) + ) + ); } - private onSelectionChanged(e: TextEditorSelectionChangeEvent) { + private onActiveLinesChanged(e: LinesChangeEvent) { void this.explorer.refreshNode(this); } }