From f20e438a9fc9a58bf43e522e78481c869ebd2ad8 Mon Sep 17 00:00:00 2001 From: Eric Gusmao Date: Sat, 7 Dec 2024 18:49:01 -0300 Subject: [PATCH] refactor: move focus and selection change handlers to event emitters in RenameCandidateListView --- .../contrib/rename/browser/renameWidget.ts | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/vs/editor/contrib/rename/browser/renameWidget.ts b/src/vs/editor/contrib/rename/browser/renameWidget.ts index e5a7bc7149750..23958103a2d0a 100644 --- a/src/vs/editor/contrib/rename/browser/renameWidget.ts +++ b/src/vs/editor/contrib/rename/browser/renameWidget.ts @@ -202,15 +202,7 @@ export class RenameWidget implements IRenameWidget, IContentWidget, IDisposable this._renameCandidateListView = this._disposables.add( new RenameCandidateListView(this._domNode, { - fontInfo: this._editor.getOption(EditorOption.fontInfo), - onFocusChange: (newSymbolName: string) => { - this._inputWithButton.input.value = newSymbolName; - this._isEditingRenameCandidate = false; // @ulugbekna: reset - }, - onSelectionChange: () => { - this._isEditingRenameCandidate = false; // @ulugbekna: because user picked a rename suggestion - this.acceptInput(false); // we don't allow preview with mouse click for now - } + fontInfo: this._editor.getOption(EditorOption.fontInfo) }) ); @@ -227,6 +219,16 @@ export class RenameWidget implements IRenameWidget, IContentWidget, IDisposable }) ); + this._disposables.add(this._renameCandidateListView.onFocusChange((newSymbolName: string) => { + this._inputWithButton.input.value = newSymbolName; + this._isEditingRenameCandidate = false; // @ulugbekna: reset + })); + + this._disposables.add(this._renameCandidateListView.onSelectionChange(() => { + this._isEditingRenameCandidate = false; // @ulugbekna: because user picked a rename suggestion + this.acceptInput(false); // we don't allow preview with mouse click for now + })); + this._label = document.createElement('div'); this._label.className = 'rename-label'; this._domNode.appendChild(this._label); @@ -675,8 +677,13 @@ class RenameCandidateListView { private readonly _disposables: DisposableStore; - // FIXME@ulugbekna: rewrite using event emitters - constructor(parent: HTMLElement, opts: { fontInfo: FontInfo; onFocusChange: (newSymbolName: string) => void; onSelectionChange: () => void }) { + private readonly _onFocusChange = new Emitter(); + public readonly onFocusChange = this._onFocusChange.event; + + private readonly _onSelectionChange = new Emitter(); + public readonly onSelectionChange = this._onSelectionChange.event; + + constructor(parent: HTMLElement, opts: { fontInfo: FontInfo }) { this._disposables = new DisposableStore(); @@ -695,7 +702,7 @@ class RenameCandidateListView { this._listWidget.onDidChangeFocus( e => { if (e.elements.length === 1) { - opts.onFocusChange(e.elements[0].newSymbolName); + this._onFocusChange.fire(e.elements[0].newSymbolName); } }, this._disposables @@ -704,7 +711,7 @@ class RenameCandidateListView { this._listWidget.onDidChangeSelection( e => { if (e.elements.length === 1) { - opts.onSelectionChange(); + this._onSelectionChange.fire(); } }, this._disposables