Skip to content
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

Add cursor change after revert or stage changes #85074

Merged
merged 4 commits into from Sep 9, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 9 additions & 3 deletions extensions/git/src/commands.ts
Expand Up @@ -6,7 +6,7 @@
import { lstat, Stats } from 'fs';
import * as os from 'os';
import * as path from 'path';
import { commands, Disposable, LineChange, MessageOptions, OutputChannel, Position, ProgressLocation, QuickPickItem, Range, SourceControlResourceState, TextDocumentShowOptions, TextEditor, Uri, ViewColumn, window, workspace, WorkspaceEdit, WorkspaceFolder } from 'vscode';
import { Selection, commands, Disposable, LineChange, MessageOptions, OutputChannel, Position, ProgressLocation, QuickPickItem, Range, SourceControlResourceState, TextDocumentShowOptions, TextEditor, Uri, ViewColumn, window, workspace, WorkspaceEdit, WorkspaceFolder } from 'vscode';
import TelemetryReporter from 'vscode-extension-telemetry';
import * as nls from 'vscode-nls';
import { Branch, GitErrorCodes, Ref, RefType, Status } from './api/git';
Expand Down Expand Up @@ -981,6 +981,9 @@ export class CommandCenter {
}

await this._stageChanges(textEditor, [changes[index]]);

const firstStagedLine = changes[index].modifiedStartLineNumber - 1;
textEditor.selections = [new Selection(firstStagedLine, 0, firstStagedLine, 0)];
}

@command('git.stageSelectedRanges', { diff: true })
Expand Down Expand Up @@ -1028,6 +1031,9 @@ export class CommandCenter {
}

await this._revertChanges(textEditor, [...changes.slice(0, index), ...changes.slice(index + 1)]);

const firstStagedLine = changes[index].modifiedStartLineNumber - 1;
textEditor.selections = [new Selection(firstStagedLine, 0, firstStagedLine, 0)];
}

@command('git.revertSelectedRanges', { diff: true })
Expand All @@ -1049,7 +1055,9 @@ export class CommandCenter {
return;
}

const selectionsBeforeRevert = textEditor.selections;
await this._revertChanges(textEditor, selectedChanges);
textEditor.selections = selectionsBeforeRevert;
}

private async _revertChanges(textEditor: TextEditor, changes: LineChange[]): Promise<void> {
Expand All @@ -1062,7 +1070,6 @@ export class CommandCenter {

const originalUri = toGitUri(modifiedUri, '~');
const originalDocument = await workspace.openTextDocument(originalUri);
const selectionsBeforeRevert = textEditor.selections;
const visibleRangesBeforeRevert = textEditor.visibleRanges;
const result = applyLineChanges(originalDocument, modifiedDocument, changes);

Expand All @@ -1072,7 +1079,6 @@ export class CommandCenter {

await modifiedDocument.save();

textEditor.selections = selectionsBeforeRevert;
textEditor.revealRange(visibleRangesBeforeRevert[0]);
}

Expand Down