Ver a proveniência

Closes #163 - stops refresh when unfocused

main
Eric Amodio há 7 anos
ascendente
cometimento
90b97abbeb
2 ficheiros alterados com 36 adições e 4 eliminações
  1. +35
    -3
      src/gitService.ts
  2. +1
    -1
      src/views/statusNode.ts

+ 35
- 3
src/gitService.ts Ver ficheiro

@ -1,6 +1,6 @@
'use strict';
import { Functions, Iterables, Objects } from './system';
import { Disposable, Event, EventEmitter, FileSystemWatcher, Range, TextDocument, TextDocumentChangeEvent, TextEditor, Uri, workspace } from 'vscode';
import { Disposable, Event, EventEmitter, FileSystemWatcher, Range, TextDocument, TextDocumentChangeEvent, TextEditor, Uri, window, WindowState, workspace } from 'vscode';
import { IConfig } from './configuration';
import { DocumentSchemes, ExtensionKey } from './constants';
import { RemoteProviderFactory } from './git/remotes/factory';
@ -84,8 +84,8 @@ export class GitService extends Disposable {
return this._onDidChangeGitCache.event;
}
private _onDidChangeFileSystem = new EventEmitter<Uri>();
get onDidChangeFileSystem(): Event<Uri> {
private _onDidChangeFileSystem = new EventEmitter<Uri | undefined>();
get onDidChangeFileSystem(): Event<Uri | undefined> {
return this._onDidChangeFileSystem.event;
}
@ -94,6 +94,9 @@ export class GitService extends Disposable {
return this._onDidChangeRepo.event;
}
private _focused: boolean = true;
private _unfocusedChanges: { repo: boolean, fs: boolean } = { repo: false, fs: false };
private _gitCache: Map<string, GitCacheEntry>;
private _remotesCache: Map<string, GitRemote[]>;
private _cacheDisposable: Disposable | undefined;
@ -117,6 +120,7 @@ export class GitService extends Disposable {
this._onConfigurationChanged();
const subscriptions: Disposable[] = [
window.onDidChangeWindowState(this._onWindowStateChanged, this),
workspace.onDidChangeConfiguration(this._onConfigurationChanged, this),
RemoteProviderFactory.onDidChange(this._onRemoteProviderChanged, this)
];
@ -192,6 +196,24 @@ export class GitService extends Disposable {
this._fireRepoChange(RepoChangedReasons.Remotes);
}
private _onWindowStateChanged(e: WindowState) {
const focusChanged = e.focused !== this._focused;
this._focused = e.focused;
if (!focusChanged || !e.focused) return;
// If we've come back into focus and we are dirty, fire the change events
if (this._unfocusedChanges.fs) {
this._unfocusedChanges.fs = false;
this._onDidChangeFileSystem.fire();
}
if (this._unfocusedChanges.repo) {
this._unfocusedChanges.repo = false;
this._fireRepoChangeDebounced!();
}
}
private _onTextDocumentChanged(e: TextDocumentChangeEvent) {
if (!this.UseCaching) return;
if (e.document.uri.scheme !== DocumentSchemes.File) return;
@ -248,6 +270,11 @@ export class GitService extends Disposable {
this._repoChangedReasons.push(reason);
}
if (!this._focused) {
this._unfocusedChanges.repo = true;
return;
}
return this._fireRepoChangeDebounced();
}
@ -1022,6 +1049,11 @@ export class GitService extends Disposable {
// Ignore .git changes
if (/\.git/.test(uri.fsPath)) return;
if (!this._focused) {
this._unfocusedChanges.fs = true;
return;
}
debouncedFn(uri);
};

+ 1
- 1
src/views/statusNode.ts Ver ficheiro

@ -102,7 +102,7 @@ export class StatusNode extends ExplorerNode {
return this.git.config.gitExplorer.includeWorkingTree;
}
private async onFileSystemChanged(uri: Uri) {
private async onFileSystemChanged(uri?: Uri) {
const status = await this.git.getStatusForRepo(this.uri.repoPath!);
// If we haven't changed from having some working changes to none or vice versa then just refresh the node

Carregando…
Cancelar
Guardar