Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move focus and selection change handlers to event emitters #235555

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions src/vs/editor/contrib/rename/browser/renameWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
);

Expand All @@ -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);
Expand Down Expand Up @@ -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<string>();
public readonly onFocusChange = this._onFocusChange.event;

private readonly _onSelectionChange = new Emitter<void>();
public readonly onSelectionChange = this._onSelectionChange.event;

constructor(parent: HTMLElement, opts: { fontInfo: FontInfo }) {

this._disposables = new DisposableStore();

Expand All @@ -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
Expand All @@ -704,7 +711,7 @@ class RenameCandidateListView {
this._listWidget.onDidChangeSelection(
e => {
if (e.elements.length === 1) {
opts.onSelectionChange();
this._onSelectionChange.fire();
}
},
this._disposables
Expand Down