未验证 提交 54871729 编写于 作者: J Johannes Rieken 提交者: GitHub

Merge pull request #95739 from ChrisPapp/rename_bug_#92507

Prevent unexpected rename cancellation
......@@ -6,7 +6,7 @@
import * as strings from 'vs/base/common/strings';
import { ICodeEditor, IActiveCodeEditor } from 'vs/editor/browser/editorBrowser';
import { Position } from 'vs/editor/common/core/position';
import { Range } from 'vs/editor/common/core/range';
import { Range, IRange } from 'vs/editor/common/core/range';
import { CancellationTokenSource, CancellationToken } from 'vs/base/common/cancellation';
import { IDisposable, DisposableStore } from 'vs/base/common/lifecycle';
import { ITextModel } from 'vs/editor/common/model';
......@@ -87,19 +87,28 @@ export class EditorState {
/**
* A cancellation token source that cancels when the editor changes as expressed
* by the provided flags
* @param range If provided, changes in position and selection within this range will not trigger cancellation
*/
export class EditorStateCancellationTokenSource extends EditorKeybindingCancellationTokenSource implements IDisposable {
private readonly _listener = new DisposableStore();
constructor(readonly editor: IActiveCodeEditor, flags: CodeEditorStateFlag, parent?: CancellationToken) {
constructor(readonly editor: IActiveCodeEditor, flags: CodeEditorStateFlag, parent?: CancellationToken, readonly range?: IRange) {
super(editor, parent);
if (flags & CodeEditorStateFlag.Position) {
this._listener.add(editor.onDidChangeCursorPosition(_ => this.cancel()));
this._listener.add(editor.onDidChangeCursorPosition(e => {
if (!this.range || !Range.containsPosition(this.range, e.position)) {
this.cancel();
}
}));
}
if (flags & CodeEditorStateFlag.Selection) {
this._listener.add(editor.onDidChangeCursorSelection(_ => this.cancel()));
this._listener.add(editor.onDidChangeCursorSelection(e => {
if (!this.range || !Range.containsRange(this.range, e.selection)) {
this.cancel();
}
}));
}
if (flags & CodeEditorStateFlag.Scroll) {
this._listener.add(editor.onDidScrollChange(_ => this.cancel()));
......
......@@ -168,6 +168,8 @@ class RenameController implements IEditorContribution {
if (this._cts.token.isCancellationRequested) {
return undefined;
}
this._cts.dispose();
this._cts = new EditorStateCancellationTokenSource(this.editor, CodeEditorStateFlag.Position | CodeEditorStateFlag.Value, undefined, loc.range);
// do rename at location
let selection = this.editor.getSelection();
......@@ -180,7 +182,7 @@ class RenameController implements IEditorContribution {
}
const supportPreview = this._bulkEditService.hasPreviewHandler() && this._configService.getValue<boolean>(this.editor.getModel().uri, 'editor.rename.enablePreview');
const inputFieldResult = await this._renameInputField.getValue().getInput(loc.range, loc.text, selectionStart, selectionEnd, supportPreview);
const inputFieldResult = await this._renameInputField.getValue().getInput(loc.range, loc.text, selectionStart, selectionEnd, supportPreview, this._cts.token);
// no result, only hint to focus the editor or not
if (typeof inputFieldResult === 'boolean') {
......
......@@ -7,7 +7,7 @@ import 'vs/css!./renameInputField';
import { DisposableStore } from 'vs/base/common/lifecycle';
import { ContentWidgetPositionPreference, ICodeEditor, IContentWidget, IContentWidgetPosition } from 'vs/editor/browser/editorBrowser';
import { Position } from 'vs/editor/common/core/position';
import { IRange, Range } from 'vs/editor/common/core/range';
import { IRange } from 'vs/editor/common/core/range';
import { ScrollType } from 'vs/editor/common/editorCommon';
import { localize } from 'vs/nls';
import { IContextKey, IContextKeyService, RawContextKey } from 'vs/platform/contextkey/common/contextkey';
......@@ -16,6 +16,7 @@ import { IColorTheme, IThemeService } from 'vs/platform/theme/common/themeServic
import { EditorOption } from 'vs/editor/common/config/editorOptions';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { toggleClass } from 'vs/base/browser/dom';
import { CancellationToken } from 'vs/base/common/cancellation';
export const CONTEXT_RENAME_INPUT_VISIBLE = new RawContextKey<boolean>('renameInputVisible', false);
......@@ -149,7 +150,7 @@ export class RenameInputField implements IContentWidget {
}
}
getInput(where: IRange, value: string, selectionStart: number, selectionEnd: number, supportPreview: boolean): Promise<RenameInputFieldResult | boolean> {
getInput(where: IRange, value: string, selectionStart: number, selectionEnd: number, supportPreview: boolean, token: CancellationToken): Promise<RenameInputFieldResult | boolean> {
toggleClass(this._domNode!, 'preview', supportPreview);
......@@ -185,14 +186,7 @@ export class RenameInputField implements IContentWidget {
});
};
let onCursorChanged = () => {
const editorPosition = this._editor.getPosition();
if (!editorPosition || !Range.containsPosition(where, editorPosition)) {
this.cancelInput(true);
}
};
disposeOnDone.add(this._editor.onDidChangeCursorSelection(onCursorChanged));
token.onCancellationRequested(() => this.cancelInput(true));
disposeOnDone.add(this._editor.onDidBlurEditorWidget(() => this.cancelInput(false)));
this._show();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册