Skip to content

Commit

Permalink
tweak undo behaviour when inserting suggestion via commit character, f…
Browse files Browse the repository at this point in the history
…ixes #44155
  • Loading branch information
jrieken committed Oct 10, 2019
1 parent a8ec0bb commit f60e33e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
16 changes: 8 additions & 8 deletions src/vs/editor/contrib/suggest/suggestController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ export class SuggestController implements IEditorContribution {
const widget = this._instantiationService.createInstance(SuggestWidget, this._editor);

this._toDispose.add(widget);
this._toDispose.add(widget.onDidSelect(item => this._insertSuggestion(item, false, true), this));
this._toDispose.add(widget.onDidSelect(item => this._insertSuggestion(item, false, true, true), this));

// Wire up logic to accept a suggestion on certain characters
const commitCharacterController = new CommitCharacterController(this._editor, widget, item => this._insertSuggestion(item, false, true));
const commitCharacterController = new CommitCharacterController(this._editor, widget, item => this._insertSuggestion(item, false, true, false));
this._toDispose.add(commitCharacterController);
this._toDispose.add(this._model.onDidSuggest(e => {
if (e.completionModel.items.length === 0) {
Expand Down Expand Up @@ -223,7 +223,7 @@ export class SuggestController implements IEditorContribution {
this._lineSuffix.dispose();
}

protected _insertSuggestion(event: ISelectedSuggestion | undefined, keepAlternativeSuggestions: boolean, undoStops: boolean): void {
protected _insertSuggestion(event: ISelectedSuggestion | undefined, keepAlternativeSuggestions: boolean, undoStopBefore: boolean, undoStopAfter: boolean): void {
if (!event || !event.item) {
this._alternatives.getValue().reset();
this._model.cancel();
Expand All @@ -242,7 +242,7 @@ export class SuggestController implements IEditorContribution {

// pushing undo stops *before* additional text edits and
// *after* the main edit
if (undoStops) {
if (undoStopBefore) {
this._editor.pushUndoStop();
}

Expand Down Expand Up @@ -270,7 +270,7 @@ export class SuggestController implements IEditorContribution {
adjustWhitespace: !(suggestion.insertTextRules! & CompletionItemInsertTextRule.KeepWhitespace)
});

if (undoStops) {
if (undoStopAfter) {
this._editor.pushUndoStop();
}

Expand Down Expand Up @@ -300,7 +300,7 @@ export class SuggestController implements IEditorContribution {
if (modelVersionNow !== model.getAlternativeVersionId()) {
model.undo();
}
this._insertSuggestion(next, false, false);
this._insertSuggestion(next, false, false, false);
break;
}
});
Expand Down Expand Up @@ -382,7 +382,7 @@ export class SuggestController implements IEditorContribution {
return;
}
this._editor.pushUndoStop();
this._insertSuggestion({ index, item, model: completionModel }, true, false);
this._insertSuggestion({ index, item, model: completionModel }, true, false, false);

}, undefined, listener);
});
Expand All @@ -394,7 +394,7 @@ export class SuggestController implements IEditorContribution {

acceptSelectedSuggestion(keepAlternativeSuggestions?: boolean): void {
const item = this._widget.getValue().getFocusedItem();
this._insertSuggestion(item, !!keepAlternativeSuggestions, true);
this._insertSuggestion(item, !!keepAlternativeSuggestions, true, true);
}

acceptNextSuggestion() {
Expand Down
2 changes: 1 addition & 1 deletion src/vs/editor/contrib/suggest/test/suggestModel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ suite('SuggestModel - TriggerAndCancelOracle', function () {
return withOracle(async (sugget, editor) => {
class TestCtrl extends SuggestController {
_insertSuggestion(item: ISelectedSuggestion) {
super._insertSuggestion(item, false, true);
super._insertSuggestion(item, false, true, true);
}
}
const ctrl = <TestCtrl>editor.registerAndInstantiateContribution(TestCtrl);
Expand Down

0 comments on commit f60e33e

Please sign in to comment.