Skip to content

Commit dd1b4e0

Browse files
committed
Fixes #4831 refines rebase editor reveal behavior
- Replaces `never` and `onOpen` reveal behaviors with a new `onDoubleClick` default to reduce automatic UI jumps - Ensures the commit graph or details view opens beside the rebase editor for a better side-by-side experience - Updates selection logic to properly notify the host when interacting with commit entries - Improves graph command handling to better manage view columns and existing panel visibility
1 parent 705a378 commit dd1b4e0

File tree

7 files changed

+64
-58
lines changed

7 files changed

+64
-58
lines changed

docs/telemetry-events.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2985,7 +2985,7 @@ void
29852985
'context.ascending': boolean,
29862986
'context.config.openOnPausedRebase': boolean | 'interactive',
29872987
'context.config.ordering': 'asc' | 'desc',
2988-
'context.config.revealBehavior': 'never' | 'onOpen' | 'onSelection',
2988+
'context.config.revealBehavior': 'onDoubleClick' | 'onSelection',
29892989
'context.config.revealLocation': 'graph' | 'inspect',
29902990
'context.webview.host': 'view' | 'editor',
29912991
'context.webview.id': string,

package.json

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3757,18 +3757,16 @@
37573757
},
37583758
"gitlens.rebaseEditor.revealBehavior": {
37593759
"type": "string",
3760-
"default": "onOpen",
3760+
"default": "onDoubleClick",
37613761
"enum": [
3762-
"never",
3763-
"onOpen",
3762+
"onDoubleClick",
37643763
"onSelection"
37653764
],
37663765
"enumDescriptions": [
3767-
"Never automatically reveals commits",
3768-
"Automatically reveals commits only when opening the editor",
3769-
"Automatically reveals commits when selection changes"
3766+
"Automatically reveals commits when double-clicking on a row",
3767+
"Automatically reveals commits when selection changes or when double-clicking on a row"
37703768
],
3771-
"markdownDescription": "Specifies when to automatically reveal commits in the preferred location",
3769+
"markdownDescription": "Specifies when to automatically reveal commits in the `#gitlens.rebaseEditor.revealLocation#` location",
37723770
"scope": "window",
37733771
"order": 20
37743772
}

src/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ interface RebaseEditorConfig {
668668
readonly openOnPausedRebase: boolean | 'interactive';
669669
readonly ordering: 'asc' | 'desc';
670670
readonly revealLocation: 'graph' | 'inspect';
671-
readonly revealBehavior: 'never' | 'onOpen' | 'onSelection';
671+
readonly revealBehavior: 'onDoubleClick' | 'onSelection';
672672
}
673673

674674
export type RemotesConfig =

src/webviews/apps/rebase/rebase.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,15 @@ export class GlRebaseEditor extends GlAppHost<State, RebaseStateProvider> {
209209
if (!this.selectedIds.has(id)) {
210210
this.selectedIds = new Set([id]);
211211
this.anchoredEntryId = id;
212+
213+
// Notify host of selection change (only for commit entries)
214+
const sortedIndex = this._idToSortedIndex.get(id) ?? -1;
215+
if (sortedIndex !== -1) {
216+
const entry = this._sortedEntries[sortedIndex];
217+
if (isCommitEntry(entry)) {
218+
this._ipc.sendCommand(UpdateSelectionCommand, { sha: entry.sha });
219+
}
220+
}
212221
return;
213222
}
214223

src/webviews/plus/graph/registration.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ export type GraphWebviewShowingArgs = [
3030
];
3131

3232
export type ShowInCommitGraphCommandArgs =
33-
| { ref: GitReference; preserveFocus?: boolean; source?: Source }
34-
| { repository: Repository; search: SearchQuery; preserveFocus?: boolean }
33+
| { ref: GitReference; preserveFocus?: boolean; source?: Source; viewColumn?: ViewColumn }
34+
| { repository: Repository; search: SearchQuery; preserveFocus?: boolean; viewColumn?: ViewColumn }
3535
| Repository
3636
| BranchNode
3737
| CommitNode
@@ -103,18 +103,30 @@ export function registerGraphWebviewCommands<T>(
103103
}
104104

105105
const preserveFocus = 'preserveFocus' in args ? (args.preserveFocus ?? false) : false;
106+
const column = 'viewColumn' in args ? args.viewColumn : undefined;
106107
if (configuration.get('graph.layout') === 'panel') {
107108
if (!container.views.graph.visible) {
108109
const instance = panels.getBestInstance({ preserveFocus: preserveFocus }, args);
109110
if (instance != null) {
110-
void instance.show({ preserveFocus: preserveFocus }, args);
111+
void instance.show({ preserveFocus: preserveFocus, column: column }, args);
111112
return;
112113
}
113114
}
114115

115116
void container.views.graph.show({ preserveFocus: preserveFocus }, args);
116117
} else {
117-
void panels.show({ preserveFocus: preserveFocus }, args);
118+
const instance = panels.getBestInstance({ preserveFocus: preserveFocus }, args);
119+
if (instance != null) {
120+
void instance.show({ preserveFocus: preserveFocus, column: column }, args);
121+
return;
122+
}
123+
124+
if (container.views.graph.visible) {
125+
void container.views.graph.show({ preserveFocus: preserveFocus }, args);
126+
return;
127+
}
128+
129+
void panels.show({ preserveFocus: preserveFocus, column: column }, args);
118130
}
119131
}
120132

src/webviews/rebase/protocol.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { Config } from '../../config';
12
import type { MergeConflict } from '../../git/models/mergeConflict';
23
import type {
34
ProcessedRebaseCommitEntry as _RebaseCommitEntry,
@@ -33,9 +34,9 @@ export interface State extends WebviewState<'gitlens.rebase'> {
3334
isReadOnly?: boolean;
3435

3536
/** Where to reveal commits when clicking on links or double-clicking rows */
36-
revealLocation: 'graph' | 'inspect';
37+
revealLocation: Config['rebaseEditor']['revealLocation'];
3738
/** When to automatically reveal commits */
38-
revealBehavior: 'never' | 'onOpen' | 'onSelection';
39+
revealBehavior: Config['rebaseEditor']['revealBehavior'];
3940

4041
/** Active rebase status - undefined if starting a new rebase */
4142
rebaseStatus?: RebaseActiveStatus;

src/webviews/rebase/rebaseWebviewProvider.ts

Lines changed: 29 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Disposable, TextDocument } from 'vscode';
2-
import { workspace } from 'vscode';
2+
import { ViewColumn, workspace } from 'vscode';
33
import { getAvatarUri, getAvatarUriFromGravatarEmail } from '../../avatars';
44
import type { RebaseEditorTelemetryContext } from '../../constants.telemetry';
55
import type { Container } from '../../container';
@@ -30,7 +30,7 @@ import type { ComposerWebviewShowingArgs } from '../plus/composer/registration';
3030
import type { ShowInCommitGraphCommandArgs } from '../plus/graph/registration';
3131
import type { IpcMessage } from '../protocol';
3232
import type { WebviewHost } from '../webviewProvider';
33-
import type { WebviewPanelShowCommandArgs, WebviewShowOptions } from '../webviewsController';
33+
import type { WebviewPanelShowCommandArgs } from '../webviewsController';
3434
import type {
3535
Author,
3636
ChangeEntriesParams,
@@ -197,14 +197,6 @@ export class RebaseWebviewProvider implements Disposable {
197197
];
198198
}
199199

200-
onShowing(loading: boolean, _options: WebviewShowOptions): [boolean, undefined] {
201-
// Reveal branch tip on initial load if behavior is 'onOpen'
202-
if (loading) {
203-
void this.revealBranchTipOnOpen();
204-
}
205-
return [true, undefined];
206-
}
207-
208200
onMessageReceived(e: IpcMessage): void {
209201
switch (true) {
210202
case AbortCommand.is(e):
@@ -525,13 +517,21 @@ export class RebaseWebviewProvider implements Disposable {
525517
name: params.ref,
526518
remote: false,
527519
});
528-
await executeCommand<ShowInCommitGraphCommandArgs>('gitlens.showInCommitGraph', { ref: ref });
520+
await executeCommand<ShowInCommitGraphCommandArgs>('gitlens.showInCommitGraph', {
521+
ref: ref,
522+
preserveFocus: true,
523+
viewColumn: ViewColumn.Beside,
524+
});
529525
return;
530526
}
531527

532528
const ref = createReference(params.ref, this.repoPath, { refType: 'revision' });
533529
if (revealIn === 'graph') {
534-
await executeCommand<ShowInCommitGraphCommandArgs>('gitlens.showInCommitGraph', { ref: ref });
530+
await executeCommand<ShowInCommitGraphCommandArgs>('gitlens.showInCommitGraph', {
531+
ref: ref,
532+
preserveFocus: true,
533+
viewColumn: ViewColumn.Beside,
534+
});
535535
} else {
536536
await this.container.views.commitDetails.show({ preserveFocus: true }, { commit: ref });
537537
}
@@ -543,8 +543,18 @@ export class RebaseWebviewProvider implements Disposable {
543543
void this.fireSelectionChangedDebounced(params);
544544
}
545545

546-
private async fireSelectionChanged(params: UpdateSelectionParams): Promise<void> {
546+
private getRevealBehavior() {
547547
const revealBehavior = configuration.get('rebaseEditor.revealBehavior');
548+
// Handle deprecated 'never' and 'onOpen' behavior
549+
if ((revealBehavior as string) === 'onOpen' || (revealBehavior as string) === 'never') {
550+
return 'onDoubleClick';
551+
}
552+
553+
return revealBehavior;
554+
}
555+
556+
private async fireSelectionChanged(params: UpdateSelectionParams): Promise<void> {
557+
const revealBehavior = this.getRevealBehavior();
548558
// Only auto-reveal on selection if behavior is 'onSelection'
549559
if (revealBehavior !== 'onSelection') return;
550560

@@ -565,7 +575,11 @@ export class RebaseWebviewProvider implements Disposable {
565575
const revealLocation = configuration.get('rebaseEditor.revealLocation');
566576
if (revealLocation === 'graph') {
567577
const ref = createReference(commit.sha, this.repoPath, { refType: 'revision' });
568-
await executeCommand<ShowInCommitGraphCommandArgs>('gitlens.showInCommitGraph', { ref: ref });
578+
await executeCommand<ShowInCommitGraphCommandArgs>('gitlens.showInCommitGraph', {
579+
ref: ref,
580+
preserveFocus: true,
581+
viewColumn: ViewColumn.Beside,
582+
});
569583
} else {
570584
// Fire event for commit details view to pick up
571585
this.container.events.fire(
@@ -637,7 +651,7 @@ export class RebaseWebviewProvider implements Disposable {
637651
ascending: this.ascending,
638652
isReadOnly: processed.preservesMerges,
639653
revealLocation: configuration.get('rebaseEditor.revealLocation'),
640-
revealBehavior: configuration.get('rebaseEditor.revealBehavior'),
654+
revealBehavior: this.getRevealBehavior(),
641655
rebaseStatus: rebaseStatus,
642656
repoPath: this.repoPath,
643657
subscription: subscription,
@@ -736,34 +750,6 @@ export class RebaseWebviewProvider implements Disposable {
736750
};
737751
}
738752

739-
private async revealBranchTipOnOpen(): Promise<void> {
740-
const revealBehavior = configuration.get('rebaseEditor.revealBehavior');
741-
if (revealBehavior !== 'onOpen') return;
742-
743-
const revealLocation = configuration.get('rebaseEditor.revealLocation');
744-
const branchName =
745-
this._branchName ??
746-
(await this.container.git.getRepositoryService(this.repoPath).branches.getBranch())?.name;
747-
if (branchName == null) return;
748-
749-
const ref = createReference(branchName, this.repoPath, { refType: 'branch', name: branchName, remote: false });
750-
751-
if (revealLocation === 'graph') {
752-
await executeCommand<ShowInCommitGraphCommandArgs>('gitlens.showInCommitGraph', { ref: ref });
753-
} else {
754-
// For inspect view, get the branch tip commit
755-
const branch = await this.container.git.getRepositoryService(this.repoPath).branches.getBranch(branchName);
756-
if (branch?.sha != null) {
757-
const commit = await this.container.git
758-
.getRepositoryService(this.repoPath)
759-
.commits.getCommit(branch.sha);
760-
if (commit != null) {
761-
await this.container.views.commitDetails.show({ preserveFocus: true }, { commit: commit });
762-
}
763-
}
764-
}
765-
}
766-
767753
private notifyDidChangeAvatars(): void {
768754
if (!this._enrichment?.authors.size || !this.host.visible) return;
769755

0 commit comments

Comments
 (0)