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 1 commit
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
19 changes: 13 additions & 6 deletions extensions/git/src/commands.ts
Original file line number Diff line number Diff line change
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 @@ -980,7 +980,10 @@ export class CommandCenter {
return;
}

await this._stageChanges(textEditor, [changes[index]]);
await this._stageChanges(textEditor, [changes[index]]).then(() => {
const firstStagedLine = changes[index].modifiedStartLineNumber - 1;
textEditor.selections = [new Selection(firstStagedLine, 0, firstStagedLine, 0)];
});
joaomoreno marked this conversation as resolved.
Show resolved Hide resolved
}

@command('git.stageSelectedRanges', { diff: true })
Expand Down Expand Up @@ -1027,7 +1030,10 @@ export class CommandCenter {
return;
}

await this._revertChanges(textEditor, [...changes.slice(0, index), ...changes.slice(index + 1)]);
await this._revertChanges(textEditor, [...changes.slice(0, index), ...changes.slice(index + 1)]).then(() => {
const firstStagedLine = changes[index].modifiedStartLineNumber - 1;
textEditor.selections = [new Selection(firstStagedLine, 0, firstStagedLine, 0)];
});
joaomoreno marked this conversation as resolved.
Show resolved Hide resolved
}

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

await this._revertChanges(textEditor, selectedChanges);
const selectionsBeforeRevert = textEditor.selections;
await this._revertChanges(textEditor, selectedChanges).then(() => {
textEditor.selections = selectionsBeforeRevert;
});
joaomoreno marked this conversation as resolved.
Show resolved Hide resolved
}

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

await modifiedDocument.save();

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

Expand Down