Browse Source

Adds sha hint to commit details

main
Keith Daulton 1 year ago
parent
commit
0c706e4afc
6 changed files with 68 additions and 3 deletions
  1. +16
    -0
      src/system/mru.ts
  2. +3
    -0
      src/webviews/apps/commitDetails/commitDetails.html
  3. +4
    -0
      src/webviews/apps/commitDetails/commitDetails.scss
  4. +16
    -0
      src/webviews/apps/commitDetails/commitDetails.ts
  5. +28
    -3
      src/webviews/commitDetails/commitDetailsWebview.ts
  6. +1
    -0
      src/webviews/commitDetails/protocol.ts

+ 16
- 0
src/system/mru.ts View File

@ -39,6 +39,22 @@ 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;
}
}
navigate(direction: 'back' | 'forward'): T | undefined {
if (this.stack.length <= 1) return undefined;

+ 3
- 0
src/webviews/apps/commitDetails/commitDetails.html View File

@ -118,6 +118,9 @@
title="Forward"
><code-icon icon="arrow-right" data-region="commit-forward"></code-icon
></a>
<a class="commit-action commit-action--emphasis-low" href="#" title="View this Commit"
><code-icon icon="git-commit"></code-icon><span data-region="commit-hint"></span
></a>
</div>
<div class="commit-details__actionbar-group">
<a

+ 4
- 0
src/webviews/apps/commitDetails/commitDetails.scss View File

@ -391,6 +391,10 @@ ul {
&.is-hidden {
display: none;
}
&--emphasis-low:not(:hover, :focus, :active) {
opacity: 0.5;
}
}
.commit-details {

+ 16
- 0
src/webviews/apps/commitDetails/commitDetails.ts View File

@ -315,6 +315,22 @@ export class CommitDetailsApp extends App> {
$forward.setAttribute('aria-hidden', 'false');
$forward.classList.toggle('is-hidden', false);
}
const $hint = document.querySelector<HTMLElement>('[data-region="commit-hint"]');
if ($hint == null) return;
const $hintAction = $hint.closest('.commit-action')!;
if (state.navigationStack.hint) {
$hint.innerText = state.navigationStack.hint;
$hintAction.setAttribute('aria-hidden', 'false');
$hintAction.classList.toggle('is-hidden', false);
$hintAction.setAttribute('data-action', state.pinned ? 'forward' : 'back');
} else {
$hint.innerText = '';
$hintAction.removeAttribute('data-action');
$hintAction.removeAttribute('title');
$hintAction.setAttribute('aria-hidden', 'true');
$hintAction.classList.toggle('is-hidden', true);
}
}
renderPin(state: CommitState) {

+ 28
- 3
src/webviews/commitDetails/commitDetailsWebview.ts View File

@ -177,14 +177,20 @@ export class CommitDetailsWebviewProvider implements WebviewProvider
private onCommitSelected(e: CommitSelectedEvent) {
if (
e.data == null ||
(this._pinned && e.data.interaction === 'passive') ||
(this.options.mode === 'graph' && e.source !== 'gitlens.views.graph') ||
(this.options.mode === 'default' && e.source === 'gitlens.views.graph')
) {
return;
}
void this.host.show(false, { preserveFocus: e.data.preserveFocus }, e.data);
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();
} else {
void this.host.show(false, { preserveFocus: e.data.preserveFocus }, e.data);
}
}
includeBootstrap(): Promise<Serialized<State>> {
@ -283,6 +289,8 @@ 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(
@ -555,7 +563,8 @@ export class CommitDetailsWebviewProvider implements WebviewProvider
this._commitStack.add(getReferenceFromRevision(commit));
}
let sha = this._commitStack.get(this._commitStack.position + 1)?.ref;
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);
}
@ -663,6 +672,22 @@ 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;
if (sha != null) {
sha = shortenRevision(sha);
}
this.updatePendingContext({
navigationStack: {
count: this._commitStack.count,
position: this._commitStack.position,
hint: sha,
},
});
this.updateState();
}
private async notifyDidChangeState() {
const scope = getLogScope();

+ 1
- 0
src/webviews/commitDetails/protocol.ts View File

@ -52,6 +52,7 @@ export type State = {
navigationStack: {
count: number;
position: number;
hint?: string;
};
};

Loading…
Cancel
Save