From a4c05af8a391900bafd28bacd07f701426a48a87 Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Wed, 14 Mar 2018 15:46:47 +0100 Subject: [PATCH] better fix for #45561 --- src/vs/editor/contrib/rename/rename.ts | 25 +++++++++-------- .../editor/contrib/rename/renameInputField.ts | 27 ++++++++++--------- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/src/vs/editor/contrib/rename/rename.ts b/src/vs/editor/contrib/rename/rename.ts index b0ec04924f4..487be5c5492 100644 --- a/src/vs/editor/contrib/rename/rename.ts +++ b/src/vs/editor/contrib/rename/rename.ts @@ -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); } } diff --git a/src/vs/editor/contrib/rename/renameInputField.ts b/src/vs/editor/contrib/rename/renameInputField.ts index c8139ddf2da..76f4feab71a 100644 --- a/src/vs/editor/contrib/rename/renameInputField.ts +++ b/src/vs/editor/contrib/rename/renameInputField.ts @@ -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 { + public getInput(where: Range, value: string, selectionStart: number, selectionEnd: number): TPromise { 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((c, e) => { + return new TPromise(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 => {