Skip to content

Commit 900fccf

Browse files
committed
add escape keybinding and improve event handling for signature tooltip
1 parent 9a1c3a6 commit 900fccf

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

packages/ace-linters/src/components/signature-tooltip.ts

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@ import {BaseTooltip} from "./base-tooltip";
33

44
export class SignatureTooltip extends BaseTooltip {
55
editorHandlers: Map<Ace.Editor, () => void> = new Map();
6+
escCommand = {
7+
exec: this.$hide,
8+
bindKey: "Esc"
9+
};
610

711
registerEditor(editor: Ace.Editor) {
812
const handler = () => this.onChangeSelection(editor);
913
this.editorHandlers.set(editor, handler);
1014
editor.on("changeSelection", handler);
15+
16+
editor.commands.addCommand(this.escCommand);
1117
}
1218

1319
unregisterEditor(editor: Ace.Editor) {
@@ -20,8 +26,9 @@ export class SignatureTooltip extends BaseTooltip {
2026
if (this.$activeEditor === editor) {
2127
this.$inactivateEditor();
2228
}
23-
}
2429

30+
editor.commands.removeCommand(this.escCommand);
31+
}
2532

2633
onChangeSelection = (editor: Ace.Editor) => {
2734
if (!this.provider.options.functionality!.signatureHelp)
@@ -54,7 +61,7 @@ export class SignatureTooltip extends BaseTooltip {
5461
// Editor was deactivated before this callback
5562
return;
5663
}
57-
64+
5865
let cursor = this.$activeEditor!.getCursorPosition();
5966
let session = this.$activeEditor!.session;
6067
let docPos = session.screenToDocumentPosition(cursor.row, cursor.column);
@@ -85,16 +92,25 @@ export class SignatureTooltip extends BaseTooltip {
8592
});
8693
}
8794

88-
$onMouseWheel = (e) => {
89-
console.log(e);
90-
setTimeout(this.$show, 0);
95+
$onAfterRender = (e) => {
96+
if (!this.isOpen) return;
97+
setTimeout(() => {
98+
if (!this.$activeEditor?.isRowVisible(this.row)) {
99+
this.$hide();
100+
} else {
101+
this.$show();
102+
}
103+
}, 0);
104+
91105
}
92106

93107
$registerEditorEvents() {
94-
this.$activeEditor!.on("mousewheel", this.$onMouseWheel);
108+
this.$activeEditor!.renderer.on("afterRender", this.$onAfterRender);
109+
this.$activeEditor!.on("blur", this.$hide);
95110
}
96111

97112
$removeEditorEvents() {
98-
this.$activeEditor!.off("mousewheel", this.$onMouseWheel);
113+
this.$activeEditor!.renderer.off("afterRender", this.$onAfterRender);
114+
this.$activeEditor!.off("blur", this.$hide);
99115
}
100116
}

0 commit comments

Comments
 (0)