mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 13:00:58 +00:00
better fix for #45561
This commit is contained in:
parent
6b7d8721f2
commit
a4c05af8a3
|
@ -6,7 +6,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
import * as nls from 'vs/nls';
|
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 { KeyMod, KeyCode } from 'vs/base/common/keyCodes';
|
||||||
import { TPromise } from 'vs/base/common/winjs.base';
|
import { TPromise } from 'vs/base/common/winjs.base';
|
||||||
import { IFileService } from 'vs/platform/files/common/files';
|
import { IFileService } from 'vs/platform/files/common/files';
|
||||||
|
@ -148,14 +148,22 @@ class RenameController implements IEditorContribution {
|
||||||
}
|
}
|
||||||
|
|
||||||
this._renameInputVisible.set(true);
|
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();
|
this._renameInputVisible.reset();
|
||||||
|
|
||||||
|
if (typeof newNameOrFocusFlag === 'boolean') {
|
||||||
|
if (newNameOrFocusFlag) {
|
||||||
|
this.editor.focus();
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
this.editor.focus();
|
this.editor.focus();
|
||||||
|
|
||||||
const edit = new BulkEdit(this.editor, null, this._textModelResolverService, this._fileService);
|
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 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 (result.rejectReason) {
|
||||||
if (state.validate(this.editor)) {
|
if (state.validate(this.editor)) {
|
||||||
MessageController.get(this.editor).showMessage(result.rejectReason, this.editor.getPosition());
|
MessageController.get(this.editor).showMessage(result.rejectReason, this.editor.getPosition());
|
||||||
|
@ -171,7 +179,7 @@ class RenameController implements IEditorContribution {
|
||||||
this.editor.setSelection(selection);
|
this.editor.setSelection(selection);
|
||||||
}
|
}
|
||||||
// alert
|
// 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 => {
|
}, err => {
|
||||||
|
@ -184,12 +192,7 @@ class RenameController implements IEditorContribution {
|
||||||
|
|
||||||
}, err => {
|
}, err => {
|
||||||
this._renameInputVisible.reset();
|
this._renameInputVisible.reset();
|
||||||
|
return TPromise.wrapError(err);
|
||||||
if (!isPromiseCanceledError(err)) {
|
|
||||||
this.editor.focus();
|
|
||||||
return TPromise.wrapError(err);
|
|
||||||
}
|
|
||||||
return undefined;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,7 +201,7 @@ class RenameController implements IEditorContribution {
|
||||||
}
|
}
|
||||||
|
|
||||||
public cancelRenameInput(): void {
|
public cancelRenameInput(): void {
|
||||||
this._renameInputField.cancelInput();
|
this._renameInputField.cancelInput(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
|
|
||||||
import 'vs/css!./renameInputField';
|
import 'vs/css!./renameInputField';
|
||||||
import { localize } from 'vs/nls';
|
import { localize } from 'vs/nls';
|
||||||
import { canceled } from 'vs/base/common/errors';
|
|
||||||
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
|
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
|
||||||
import { TPromise } from 'vs/base/common/winjs.base';
|
import { TPromise } from 'vs/base/common/winjs.base';
|
||||||
import { Range } from 'vs/editor/common/core/range';
|
import { Range } from 'vs/editor/common/core/range';
|
||||||
|
@ -110,7 +109,7 @@ export default class RenameInputField implements IContentWidget, IDisposable {
|
||||||
}
|
}
|
||||||
|
|
||||||
private _currentAcceptInput: () => void = null;
|
private _currentAcceptInput: () => void = null;
|
||||||
private _currentCancelInput: () => void = null;
|
private _currentCancelInput: (focusEditor) => void = null;
|
||||||
|
|
||||||
public acceptInput(): void {
|
public acceptInput(): void {
|
||||||
if (this._currentAcceptInput) {
|
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) {
|
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._position = new Position(where.startLineNumber, where.startColumn);
|
||||||
this._inputField.value = value;
|
this._inputField.value = value;
|
||||||
|
@ -140,39 +139,41 @@ export default class RenameInputField implements IContentWidget, IDisposable {
|
||||||
this._hide();
|
this._hide();
|
||||||
};
|
};
|
||||||
|
|
||||||
return new TPromise<string>((c, e) => {
|
return new TPromise<string>(resolve => {
|
||||||
|
|
||||||
this._currentCancelInput = () => {
|
this._currentCancelInput = (focusEditor) => {
|
||||||
this._currentAcceptInput = null;
|
this._currentAcceptInput = null;
|
||||||
this._currentCancelInput = null;
|
this._currentCancelInput = null;
|
||||||
e(canceled());
|
resolve(focusEditor);
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
this._currentAcceptInput = () => {
|
this._currentAcceptInput = () => {
|
||||||
if (this._inputField.value.trim().length === 0 || this._inputField.value === value) {
|
if (this._inputField.value.trim().length === 0 || this._inputField.value === value) {
|
||||||
// empty or whitespace only or not changed
|
// empty or whitespace only or not changed
|
||||||
this.cancelInput();
|
this.cancelInput(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._currentAcceptInput = null;
|
this._currentAcceptInput = null;
|
||||||
this._currentCancelInput = null;
|
this._currentCancelInput = null;
|
||||||
c(this._inputField.value);
|
resolve(this._inputField.value);
|
||||||
};
|
};
|
||||||
|
|
||||||
let onCursorChanged = () => {
|
let onCursorChanged = () => {
|
||||||
if (!Range.containsPosition(where, this._editor.getPosition())) {
|
if (!Range.containsPosition(where, this._editor.getPosition())) {
|
||||||
this.cancelInput();
|
this.cancelInput(true);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
disposeOnDone.push(this._editor.onDidChangeCursorSelection(onCursorChanged));
|
disposeOnDone.push(this._editor.onDidChangeCursorSelection(onCursorChanged));
|
||||||
disposeOnDone.push(this._editor.onDidBlurEditor(() => this.cancelInput()));
|
disposeOnDone.push(this._editor.onDidBlurEditor(() => this.cancelInput(false)));
|
||||||
|
|
||||||
this._show();
|
this._show();
|
||||||
|
|
||||||
}, this._currentCancelInput).then(newValue => {
|
}, () => {
|
||||||
|
this._currentCancelInput(true);
|
||||||
|
}).then(newValue => {
|
||||||
always();
|
always();
|
||||||
return newValue;
|
return newValue;
|
||||||
}, err => {
|
}, err => {
|
||||||
|
|
Loading…
Reference in a new issue