-
Notifications
You must be signed in to change notification settings - Fork 729
Preserve PR diff scroll position #8618
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
raashish1601
wants to merge
1
commit into
microsoft:main
from
raashish1601:fix/pr-tree-preserve-scroll-8206
+101
−15
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All rights reserved. | ||
| * Licensed under the MIT License. See License.txt in the project root for license information. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| import { strict as assert } from 'assert'; | ||
| import * as vscode from 'vscode'; | ||
| import { clearPullRequestDiffViewStates, getPullRequestDiffViewState, storePullRequestDiffViewState } from '../../view/treeNodes/fileChangeNode'; | ||
|
|
||
| describe('fileChangeNode diff view state', function () { | ||
| beforeEach(function () { | ||
| clearPullRequestDiffViewStates(); | ||
| }); | ||
|
|
||
| afterEach(function () { | ||
| clearPullRequestDiffViewStates(); | ||
| }); | ||
|
|
||
| it('stores diff view state per original and modified uri pair', function () { | ||
| const original = vscode.Uri.parse('review:/repo/file.ts?base=true'); | ||
| const modified = vscode.Uri.parse('review:/repo/file.ts?base=false'); | ||
| const range = new vscode.Range(10, 0, 25, 0); | ||
|
|
||
| storePullRequestDiffViewState(original, modified, range); | ||
|
|
||
| assert.deepStrictEqual(getPullRequestDiffViewState(original, modified), range); | ||
| assert.strictEqual(getPullRequestDiffViewState(original, vscode.Uri.parse('review:/repo/file.ts?base=false&other=true')), undefined); | ||
| }); | ||
|
|
||
| it('overwrites the saved state for the same diff pair', function () { | ||
| const original = vscode.Uri.parse('review:/repo/file.ts?base=true'); | ||
| const modified = vscode.Uri.parse('review:/repo/file.ts?base=false'); | ||
| const firstRange = new vscode.Range(1, 0, 5, 0); | ||
| const secondRange = new vscode.Range(20, 0, 30, 0); | ||
|
|
||
| storePullRequestDiffViewState(original, modified, firstRange); | ||
| storePullRequestDiffViewState(original, modified, secondRange); | ||
|
|
||
| assert.deepStrictEqual(getPullRequestDiffViewState(original, modified), secondRange); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,24 @@ import { IResolvedPullRequestModel, PullRequestModel } from '../../github/pullRe | |
| import { FileChangeModel, GitFileChangeModel, InMemFileChangeModel, RemoteFileChangeModel } from '../fileChangeModel'; | ||
| import { TreeNode, TreeNodeParent } from './treeNode'; | ||
|
|
||
| const pullRequestDiffViewStates = new Map<string, vscode.Range>(); | ||
|
|
||
| export function getPullRequestDiffViewStateKey(original: vscode.Uri, modified: vscode.Uri): string { | ||
| return `${original.toString()}::${modified.toString()}`; | ||
| } | ||
|
|
||
| export function storePullRequestDiffViewState(original: vscode.Uri, modified: vscode.Uri, visibleRange: vscode.Range): void { | ||
| pullRequestDiffViewStates.set(getPullRequestDiffViewStateKey(original, modified), visibleRange); | ||
| } | ||
|
|
||
| export function getPullRequestDiffViewState(original: vscode.Uri, modified: vscode.Uri): vscode.Range | undefined { | ||
| return pullRequestDiffViewStates.get(getPullRequestDiffViewStateKey(original, modified)); | ||
| } | ||
|
|
||
| export function clearPullRequestDiffViewStates(): void { | ||
| pullRequestDiffViewStates.clear(); | ||
| } | ||
|
|
||
| export function openFileCommand(uri: vscode.Uri, inputOpts: vscode.TextDocumentShowOptions = {}): vscode.Command { | ||
| const activeTextEditor = vscode.window.activeTextEditor; | ||
| const opts = { | ||
|
|
@@ -294,13 +312,11 @@ export class InMemFileChangeNode extends FileChangeNode implements vscode.TreeIt | |
| if (this.status === GitChangeType.ADD) { | ||
| this.command = openFileCommand(this.changeModel.filePath); | ||
| } else { | ||
| this.command = await openDiffCommand( | ||
| this.folderRepositoryManager, | ||
| this.changeModel.parentFilePath, | ||
| this.changeModel.filePath, | ||
| undefined, | ||
| this.changeModel.status, | ||
| ); | ||
| this.command = { | ||
| command: 'pr.openDiffView', | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should continue to use the |
||
| arguments: [this], | ||
| title: 'Open Changed File in pull request', | ||
| }; | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -408,13 +424,11 @@ export class GitFileChangeNode extends FileChangeNode implements vscode.TreeItem | |
| } else { | ||
| const openDiff = vscode.workspace.getConfiguration(GIT, this.pullRequestManager.repository.rootUri).get(OPEN_DIFF_ON_CLICK, true); | ||
| if (openDiff && this.status !== GitChangeType.ADD) { | ||
| this.command = await openDiffCommand( | ||
| this.pullRequestManager, | ||
| this.changeModel.parentFilePath, | ||
| this.changeModel.filePath, | ||
| this.opts, | ||
| this.status, | ||
| ); | ||
| this.command = { | ||
| command: 'pr.openDiffView', | ||
| arguments: [this], | ||
| title: 'Open Changed File in pull request', | ||
| }; | ||
| } else { | ||
| this.command = this.openFileCommand(); | ||
| } | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should try to avoid adding globals like this.