Skip to content

Commit a8cfda5

Browse files
committed
fix: escape key closes hints without blocking typing
1 parent dd767a2 commit a8cfda5

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

client/modules/IDE/components/show-hint.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,21 @@
2424

2525
// This is the old interface, kept around for now to stay
2626
// backwards-compatible.
27+
28+
//event listener to enable escape key functionality
29+
function addEscapeKeyListener(cm) {
30+
const escapeHandler = (event) => {
31+
if (event.key === 'Escape' && cm.state.completionActive) {
32+
cm.closeHint(); // Close the hint
33+
cm.focus(); // Ensure the editor regains focus
34+
document.removeEventListener('keydown', escapeHandler); // Clean up listener
35+
}
36+
};
37+
38+
// Add the event listener when hints are active
39+
document.addEventListener('keydown', escapeHandler);
40+
}
41+
2742
CodeMirror.showHint = function (cm, getHints, options) {
2843
if (!getHints) return cm.showHint(options);
2944
if (options && options.async) getHints.async = true;
@@ -55,6 +70,8 @@
5570

5671
CodeMirror.signal(this, 'startCompletion', this);
5772
completion.update(true);
73+
// Add Escape key listener
74+
addEscapeKeyListener(this);
5875
});
5976

6077
CodeMirror.defineExtension('closeHint', function () {

0 commit comments

Comments
 (0)