浏览代码

Fixes issues with commit details sha hint

main
Eric Amodio 1年前
父节点
当前提交
b4ab012d6c
共有 2 个文件被更改,包括 13 次插入37 次删除
  1. +8
    -16
      src/system/mru.ts
  2. +5
    -21
      src/webviews/commitDetails/commitDetailsWebview.ts

+ 8
- 16
src/system/mru.ts 查看文件

@ -13,14 +13,13 @@ export class MRU {
}
add(item: T): void {
const index =
this.comparator != null ? this.stack.findIndex(i => this.comparator!(item, i)) : this.stack.indexOf(item);
if (this._position > 0) {
this.stack.splice(0, this._position);
this._position = 0;
}
const index =
this.comparator != null ? this.stack.findIndex(i => this.comparator!(item, i)) : this.stack.indexOf(item);
if (index !== -1) {
this.stack.splice(index, 1);
} else if (this.stack.length === this.maxSize) {
@ -39,20 +38,13 @@ export class MRU {
return this.stack.length > 0 ? this.stack[0] : undefined;
}
insert(item: T, ref?: T): void {
const index =
ref == null
? -1
: this.comparator != null
? this.stack.findIndex(i => this.comparator!(ref, i))
: this.stack.indexOf(ref);
if (index === -1) {
this.add(item);
this._position = 1;
} else {
this.stack.splice(index, 0, item);
this._position = index + 1;
insert(item: T): void {
if (this._position > 0) {
this.stack.splice(0, this._position);
this._position = 0;
}
this.stack.unshift(item);
this._position++;
}
navigate(direction: 'back' | 'forward'): T | undefined {

+ 5
- 21
src/webviews/commitDetails/commitDetailsWebview.ts 查看文件

@ -184,10 +184,8 @@ export class CommitDetailsWebviewProvider implements WebviewProvider
}
if (this._pinned && e.data.interaction === 'passive') {
console.log('[stack] add to stack');
const current = this._commitStack.get();
this._commitStack.insert(getReferenceFromRevision(e.data.commit), current);
this.updateNavigationStack();
this._commitStack.insert(getReferenceFromRevision(e.data.commit));
this.updateNavigation();
} else {
void this.host.show(false, { preserveFocus: e.data.preserveFocus }, e.data);
}
@ -289,8 +287,6 @@ export class CommitDetailsWebviewProvider implements WebviewProvider
if (this._pinned) return;
if (this._pinned) return;
if (this.options.mode !== 'graph') {
const { lineTracker } = this.container;
this._lineTrackerDisposable = lineTracker.subscribe(
@ -563,18 +559,7 @@ export class CommitDetailsWebviewProvider implements WebviewProvider
this._commitStack.add(getReferenceFromRevision(commit));
}
const hintPosition = this._pinned ? this._commitStack.position - 1 : this._commitStack.position + 1;
let sha = this._commitStack.get(hintPosition)?.ref;
if (sha != null) {
sha = shortenRevision(sha);
}
this.updatePendingContext({
navigationStack: {
count: this._commitStack.count,
position: this._commitStack.position,
hint: sha,
},
});
this.updateNavigation();
}
this.updateState(options?.immediate ?? true);
}
@ -672,9 +657,8 @@ export class CommitDetailsWebviewProvider implements WebviewProvider
this._notifyDidChangeStateDebounced();
}
private updateNavigationStack() {
const hintPosition = this._pinned ? this._commitStack.position - 1 : this._commitStack.position + 1;
let sha = this._commitStack.get(hintPosition)?.ref;
private updateNavigation() {
let sha = this._commitStack.get(this._commitStack.position - 1)?.ref;
if (sha != null) {
sha = shortenRevision(sha);
}

正在加载...
取消
保存