Selaa lähdekoodia

Fixes more issues with file history pinning

main
Eric Amodio 4 vuotta sitten
vanhempi
commit
5fc7c5af65
5 muutettua tiedostoa jossa 81 lisäystä ja 65 poistoa
  1. +2
    -2
      package.json
  2. +1
    -0
      src/constants.ts
  3. +10
    -5
      src/views/fileHistoryView.ts
  4. +42
    -38
      src/views/nodes/fileHistoryTrackerNode.ts
  5. +26
    -20
      src/views/nodes/lineHistoryTrackerNode.ts

+ 2
- 2
package.json Näytä tiedosto

@ -5971,12 +5971,12 @@
},
{
"command": "gitlens.views.fileHistory.setEditorFollowingOn",
"when": "view =~ /^gitlens\\.views\\.fileHistory/ && !gitlens:views:fileHistory:editorFollowing",
"when": "view =~ /^gitlens\\.views\\.fileHistory/ && gitlens:views:fileHistory:canPin && !gitlens:views:fileHistory:editorFollowing",
"group": "navigation@10"
},
{
"command": "gitlens.views.fileHistory.setEditorFollowingOff",
"when": "view =~ /^gitlens\\.views\\.fileHistory/ && gitlens:views:fileHistory:editorFollowing",
"when": "view =~ /^gitlens\\.views\\.fileHistory/ && gitlens:views:fileHistory:canPin && gitlens:views:fileHistory:editorFollowing",
"group": "navigation@10"
},
{

+ 1
- 0
src/constants.ts Näytä tiedosto

@ -44,6 +44,7 @@ export enum ContextKeys {
ViewsCanCompare = 'gitlens:views:canCompare',
ViewsCanCompareFile = 'gitlens:views:canCompare:file',
ViewsCommitsMyCommitsOnly = 'gitlens:views:commits:myCommitsOnly',
ViewsFileHistoryCanPin = 'gitlens:views:fileHistory:canPin',
ViewsFileHistoryCursorFollowing = 'gitlens:views:fileHistory:cursorFollowing',
ViewsFileHistoryEditorFollowing = 'gitlens:views:fileHistory:editorFollowing',
ViewsLineHistoryEditorFollowing = 'gitlens:views:lineHistory:editorFollowing',

+ 10
- 5
src/views/fileHistoryView.ts Näytä tiedosto

@ -101,14 +101,17 @@ export class FileHistoryView extends ViewBase
return true;
}
async showHistoryForUri(uri: GitUri, baseRef?: string) {
async showHistoryForUri(uri: GitUri) {
this.setCursorFollowing(false);
this.setEditorFollowing(false);
const root = this.ensureRoot(true);
if (root instanceof FileHistoryTrackerNode) {
await root.showHistoryForUri(uri, baseRef);
await root.showHistoryForUri(uri);
this.setEditorFollowing(false);
}
return this.show();
}
@ -129,17 +132,19 @@ export class FileHistoryView extends ViewBase
}
private setEditorFollowing(enabled: boolean) {
const root = this.ensureRoot();
if (!root.hasUri) return;
this._followEditor = enabled;
void setContext(ContextKeys.ViewsFileHistoryEditorFollowing, enabled);
const root = this.ensureRoot(true);
root.setEditorFollowing(enabled);
if (this.description?.endsWith(pinnedSuffix)) {
if (enabled) {
this.description = this.description.substr(0, this.description.length - pinnedSuffix.length);
}
} else if (!enabled) {
} else if (!enabled && this.description != null) {
this.description += pinnedSuffix;
}

+ 42
- 38
src/views/nodes/fileHistoryTrackerNode.ts Näytä tiedosto

@ -1,6 +1,5 @@
'use strict';
import { Disposable, TextEditor, TreeItem, TreeItemCollapsibleState, window } from 'vscode';
import { MessageNode } from './common';
import { UriComparer } from '../../comparers';
import { BranchSorting, TagSorting } from '../../configuration';
import { Container } from '../../container';
@ -12,11 +11,11 @@ import { Logger } from '../../logger';
import { ReferencePicker } from '../../quickpicks';
import { debug, Functions, gate, log } from '../../system';
import { ContextValues, SubscribeableViewNode, unknownGitUri, ViewNode } from './viewNode';
import { ContextKeys, setContext } from '../../constants';
export class FileHistoryTrackerNode extends SubscribeableViewNode<FileHistoryView> {
private _base: string | undefined;
private _child: FileHistoryNode | undefined;
private _fileUri: GitUri | undefined;
protected splatted = true;
constructor(view: FileHistoryView) {
@ -39,27 +38,29 @@ export class FileHistoryTrackerNode extends SubscribeableViewNode
async getChildren(): Promise<ViewNode[]> {
if (this._child == null) {
if (this._fileUri == null && this.uri === unknownGitUri) {
if (!this.hasUri) {
this.view.description = undefined;
return [
new MessageNode(
this.view,
this,
'There are no editors open that can provide file history information.',
),
];
this.view.message = 'There are no editors open that can provide file history information.';
return [];
}
const uri = this._fileUri ?? this.uri;
const commitish: GitCommitish = { ...uri, repoPath: uri.repoPath!, sha: this._base ?? uri.sha };
const fileUri = new GitUri(uri, commitish);
this.view.message = undefined;
const commitish: GitCommitish = {
...this.uri,
repoPath: this.uri.repoPath!,
sha: this._base ?? this.uri.sha,
};
const fileUri = new GitUri(this.uri, commitish);
let branch;
if (!commitish.sha || commitish.sha === 'HEAD') {
branch = await Container.git.getBranch(uri.repoPath);
branch = await Container.git.getBranch(this.uri.repoPath);
} else if (!GitRevision.isSha(commitish.sha)) {
[branch] = await Container.git.getBranches(uri.repoPath, { filter: b => b.name === commitish.sha });
[branch] = await Container.git.getBranches(this.uri.repoPath, {
filter: b => b.name === commitish.sha,
});
}
this._child = new FileHistoryNode(fileUri, this.view, this, branch);
}
@ -80,6 +81,10 @@ export class FileHistoryTrackerNode extends SubscribeableViewNode
return this.canSubscribe;
}
get hasUri(): boolean {
return this._uri != unknownGitUri;
}
@gate()
@log()
async changeBase() {
@ -107,7 +112,7 @@ export class FileHistoryTrackerNode extends SubscribeableViewNode
}
if (this._child == null) return;
this._uri = unknownGitUri;
this.setUri();
await this.triggerChange();
}
@ -119,31 +124,31 @@ export class FileHistoryTrackerNode extends SubscribeableViewNode
const cc = Logger.getCorrelationContext();
if (reset) {
this._uri = unknownGitUri;
this.setUri();
this.resetChild();
}
const editor = window.activeTextEditor;
if (editor == null || !Container.git.isTrackable(editor.document.uri)) {
if (
this.uri === unknownGitUri ||
!this.hasUri ||
(Container.git.isTrackable(this.uri) &&
window.visibleTextEditors.some(e => e.document?.uri.path === this.uri.path))
) {
return true;
}
this._uri = unknownGitUri;
this.setUri();
this.resetChild();
if (cc !== undefined) {
if (cc != null) {
cc.exitDetails = `, uri=${Logger.toLoggable(this._uri)}`;
}
return false;
}
if (editor.document.uri.path === this.uri.path) {
if (cc !== undefined) {
if (cc != null) {
cc.exitDetails = `, uri=${Logger.toLoggable(this._uri)}`;
}
return true;
@ -152,26 +157,26 @@ export class FileHistoryTrackerNode extends SubscribeableViewNode
let gitUri = await GitUri.fromUri(editor.document.uri);
let uri;
if (gitUri.sha !== undefined) {
if (gitUri.sha != null) {
// If we have a sha, normalize the history to the working file (so we get a full history all the time)
const workingUri = await Container.git.getWorkingUri(gitUri.repoPath!, gitUri);
if (workingUri !== undefined) {
if (workingUri != null) {
uri = workingUri;
}
}
if (this.uri !== unknownGitUri && UriComparer.equals(uri ?? gitUri, this.uri)) {
if (this.hasUri && UriComparer.equals(uri ?? gitUri, this.uri)) {
return true;
}
if (uri !== undefined) {
if (uri != null) {
gitUri = await GitUri.fromUri(uri);
}
this._uri = gitUri;
this.setUri(gitUri);
this.resetChild();
if (cc !== undefined) {
if (cc != null) {
cc.exitDetails = `, uri=${Logger.toLoggable(this._uri)}`;
}
return false;
@ -179,11 +184,8 @@ export class FileHistoryTrackerNode extends SubscribeableViewNode
@log()
setEditorFollowing(enabled: boolean) {
if (enabled && this._fileUri !== undefined) {
this._fileUri = undefined;
this._base = undefined;
this._uri = unknownGitUri;
if (enabled) {
this.setUri();
// Don't need to call triggerChange here, since canSubscribe will do it
}
@ -191,18 +193,15 @@ export class FileHistoryTrackerNode extends SubscribeableViewNode
}
@log()
async showHistoryForUri(uri: GitUri, baseRef?: string) {
this._fileUri = uri;
this._base = baseRef;
this._uri = unknownGitUri;
async showHistoryForUri(uri: GitUri) {
this.setUri(uri);
await this.triggerChange();
}
@debug()
protected subscribe() {
return Disposable.from(
window.onDidChangeActiveTextEditor(Functions.debounce(this.onActiveEditorChanged, 500), this),
window.onDidChangeActiveTextEditor(Functions.debounce(this.onActiveEditorChanged, 250), this),
);
}
@ -210,4 +209,9 @@ export class FileHistoryTrackerNode extends SubscribeableViewNode
private onActiveEditorChanged(_editor: TextEditor | undefined) {
void this.triggerChange();
}
private setUri(uri?: GitUri) {
this._uri = uri ?? unknownGitUri;
void setContext(ContextKeys.ViewsFileHistoryCanPin, this.hasUri);
}
}

+ 26
- 20
src/views/nodes/lineHistoryTrackerNode.ts Näytä tiedosto

@ -1,6 +1,5 @@
'use strict';
import { Selection, TreeItem, TreeItemCollapsibleState, window } from 'vscode';
import { MessageNode } from './common';
import { UriComparer } from '../../comparers';
import { BranchSorting, TagSorting } from '../../configuration';
import { Container } from '../../container';
@ -14,6 +13,7 @@ import { ReferencePicker } from '../../quickpicks';
import { debug, Functions, gate, log } from '../../system';
import { LinesChangeEvent } from '../../trackers/gitLineTracker';
import { ContextValues, SubscribeableViewNode, unknownGitUri, ViewNode } from './viewNode';
import { ContextKeys, setContext } from '../../constants';
export class LineHistoryTrackerNode extends SubscribeableViewNode<LineHistoryView | FileHistoryView> {
private _base: string | undefined;
@ -42,18 +42,15 @@ export class LineHistoryTrackerNode extends SubscribeableViewNode
async getChildren(): Promise<ViewNode[]> {
if (this._child == null) {
if (this.uri === unknownGitUri) {
if (!this.hasUri) {
this.view.description = undefined;
return [
new MessageNode(
this.view,
this,
'There are no editors open that can provide line history information.',
),
];
this.view.message = 'There are no editors open that can provide line history information.';
return [];
}
this.view.message = undefined;
const commitish: GitCommitish = {
...this.uri,
repoPath: this.uri.repoPath!,
@ -90,6 +87,10 @@ export class LineHistoryTrackerNode extends SubscribeableViewNode
return this.canSubscribe;
}
get hasUri(): boolean {
return this._uri != unknownGitUri;
}
@gate()
@log()
async changeBase() {
@ -117,7 +118,7 @@ export class LineHistoryTrackerNode extends SubscribeableViewNode
}
if (this._child == null) return;
this._uri = unknownGitUri;
this.setUri();
await this.triggerChange();
}
@ -129,7 +130,7 @@ export class LineHistoryTrackerNode extends SubscribeableViewNode
const cc = Logger.getCorrelationContext();
if (reset) {
this._uri = unknownGitUri;
this.setUri();
this._editorContents = undefined;
this._selection = undefined;
this.resetChild();
@ -138,19 +139,19 @@ export class LineHistoryTrackerNode extends SubscribeableViewNode
const editor = window.activeTextEditor;
if (editor == null || !Container.git.isTrackable(editor.document.uri)) {
if (
this.uri === unknownGitUri ||
!this.hasUri ||
(Container.git.isTrackable(this.uri) &&
window.visibleTextEditors.some(e => e.document?.uri.path === this.uri.path))
) {
return true;
}
this._uri = unknownGitUri;
this.setUri();
this._editorContents = undefined;
this._selection = undefined;
this.resetChild();
if (cc !== undefined) {
if (cc != null) {
cc.exitDetails = `, uri=${Logger.toLoggable(this._uri)}`;
}
return false;
@ -158,10 +159,10 @@ export class LineHistoryTrackerNode extends SubscribeableViewNode
if (
editor.document.uri.path === this.uri.path &&
this._selection !== undefined &&
this._selection != null &&
editor.selection.isEqual(this._selection)
) {
if (cc !== undefined) {
if (cc != null) {
cc.exitDetails = `, uri=${Logger.toLoggable(this._uri)}`;
}
return true;
@ -170,20 +171,20 @@ export class LineHistoryTrackerNode extends SubscribeableViewNode
const gitUri = await GitUri.fromUri(editor.document.uri);
if (
this.uri !== unknownGitUri &&
this.hasUri &&
UriComparer.equals(gitUri, this.uri) &&
this._selection !== undefined &&
this._selection != null &&
editor.selection.isEqual(this._selection)
) {
return true;
}
this._uri = gitUri;
this.setUri(gitUri);
this._editorContents = editor.document.isDirty ? editor.document.getText() : undefined;
this._selection = editor.selection;
this.resetChild();
if (cc !== undefined) {
if (cc != null) {
cc.exitDetails = `, uri=${Logger.toLoggable(this._uri)}`;
}
return false;
@ -221,4 +222,9 @@ export class LineHistoryTrackerNode extends SubscribeableViewNode
private onActiveLinesChanged(_e: LinesChangeEvent) {
void this.triggerChange();
}
private setUri(uri?: GitUri) {
this._uri = uri ?? unknownGitUri;
void setContext(ContextKeys.ViewsFileHistoryCanPin, this.hasUri);
}
}

Ladataan…
Peruuta
Tallenna