better fix for #45561

This commit is contained in:
Johannes Rieken 2018-03-14 15:46:47 +01:00
parent 6b7d8721f2
commit a4c05af8a3
2 changed files with 28 additions and 24 deletions

View file

@ -6,7 +6,7 @@
'use strict';
import * as nls from 'vs/nls';
import { isPromiseCanceledError, illegalArgument } from 'vs/base/common/errors';
import { illegalArgument } from 'vs/base/common/errors';
import { KeyMod, KeyCode } from 'vs/base/common/keyCodes';
import { TPromise } from 'vs/base/common/winjs.base';
import { IFileService } from 'vs/platform/files/common/files';
@ -148,14 +148,22 @@ class RenameController implements IEditorContribution {
}
this._renameInputVisible.set(true);
return this._renameInputField.getInput(Range.lift(initialValue.range), initialValue.text, selectionStart, selectionEnd).then(newName => {
return this._renameInputField.getInput(Range.lift(initialValue.range), initialValue.text, selectionStart, selectionEnd).then(newNameOrFocusFlag => {
this._renameInputVisible.reset();
if (typeof newNameOrFocusFlag === 'boolean') {
if (newNameOrFocusFlag) {
this.editor.focus();
}
return undefined;
}
this.editor.focus();
const edit = new BulkEdit(this.editor, null, this._textModelResolverService, this._fileService);
const state = new EditorState(this.editor, CodeEditorStateFlag.Position | CodeEditorStateFlag.Value | CodeEditorStateFlag.Selection | CodeEditorStateFlag.Scroll);
const renameOperation = skeleton.provideRenameEdits(newName).then(result => {
const renameOperation = skeleton.provideRenameEdits(newNameOrFocusFlag).then(result => {
if (result.rejectReason) {
if (state.validate(this.editor)) {
MessageController.get(this.editor).showMessage(result.rejectReason, this.editor.getPosition());
@ -171,7 +179,7 @@ class RenameController implements IEditorContribution {
this.editor.setSelection(selection);
}
// alert
alert(nls.localize('aria', "Successfully renamed '{0}' to '{1}'. Summary: {2}", initialValue.text, newName, edit.ariaMessage()));
alert(nls.localize('aria', "Successfully renamed '{0}' to '{1}'. Summary: {2}", initialValue.text, newNameOrFocusFlag, edit.ariaMessage()));
});
}, err => {
@ -184,12 +192,7 @@ class RenameController implements IEditorContribution {
}, err => {
this._renameInputVisible.reset();
if (!isPromiseCanceledError(err)) {
this.editor.focus();
return TPromise.wrapError(err);
}
return undefined;
return TPromise.wrapError(err);
});
}
@ -198,7 +201,7 @@ class RenameController implements IEditorContribution {
}
public cancelRenameInput(): void {
this._renameInputField.cancelInput();
this._renameInputField.cancelInput(true);
}
}

View file

@ -7,7 +7,6 @@
import 'vs/css!./renameInputField';
import { localize } from 'vs/nls';
import { canceled } from 'vs/base/common/errors';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { TPromise } from 'vs/base/common/winjs.base';
import { Range } from 'vs/editor/common/core/range';
@ -110,7 +109,7 @@ export default class RenameInputField implements IContentWidget, IDisposable {
}
private _currentAcceptInput: () => void = null;
private _currentCancelInput: () => void = null;
private _currentCancelInput: (focusEditor) => void = null;
public acceptInput(): void {
if (this._currentAcceptInput) {
@ -118,13 +117,13 @@ export default class RenameInputField implements IContentWidget, IDisposable {
}
}
public cancelInput(): void {
public cancelInput(focusEditor: boolean): void {
if (this._currentCancelInput) {
this._currentCancelInput();
this._currentCancelInput(focusEditor);
}
}
public getInput(where: Range, value: string, selectionStart: number, selectionEnd: number): TPromise<string> {
public getInput(where: Range, value: string, selectionStart: number, selectionEnd: number): TPromise<string | boolean> {
this._position = new Position(where.startLineNumber, where.startColumn);
this._inputField.value = value;
@ -140,39 +139,41 @@ export default class RenameInputField implements IContentWidget, IDisposable {
this._hide();
};
return new TPromise<string>((c, e) => {
return new TPromise<string>(resolve => {
this._currentCancelInput = () => {
this._currentCancelInput = (focusEditor) => {
this._currentAcceptInput = null;
this._currentCancelInput = null;
e(canceled());
resolve(focusEditor);
return true;
};
this._currentAcceptInput = () => {
if (this._inputField.value.trim().length === 0 || this._inputField.value === value) {
// empty or whitespace only or not changed
this.cancelInput();
this.cancelInput(true);
return;
}
this._currentAcceptInput = null;
this._currentCancelInput = null;
c(this._inputField.value);
resolve(this._inputField.value);
};
let onCursorChanged = () => {
if (!Range.containsPosition(where, this._editor.getPosition())) {
this.cancelInput();
this.cancelInput(true);
}
};
disposeOnDone.push(this._editor.onDidChangeCursorSelection(onCursorChanged));
disposeOnDone.push(this._editor.onDidBlurEditor(() => this.cancelInput()));
disposeOnDone.push(this._editor.onDidBlurEditor(() => this.cancelInput(false)));
this._show();
}, this._currentCancelInput).then(newValue => {
}, () => {
this._currentCancelInput(true);
}).then(newValue => {
always();
return newValue;
}, err => {