MCPcopy Create free account
hub / github.com/Exafunction/codeium-chrome / keydownHandler

Method keydownHandler

src/jupyterlabPlugin.ts:80–142  ·  view source on GitHub ↗
(editor: CodeEditor.IEditor, event: KeyboardEvent)

Source from the content-addressed store, hash-verified

78 }
79
80 keydownHandler(editor: CodeEditor.IEditor, event: KeyboardEvent): boolean {
81 // To support the Ctrl+Space shortcut.
82 // TODO(prem): Make this a command.
83 const codeMirrorEditor = editor as CodeMirrorEditor;
84 const { consumeEvent, forceTriggerCompletion } = this.codeMirrorManager.beforeMainKeyHandler(
85 codeMirrorEditor.doc,
86 event,
87 { tab: false, escape: false }
88 );
89 if (consumeEvent !== undefined) {
90 return consumeEvent;
91 }
92 const oldString = codeMirrorEditor.doc.getValue();
93 // We need to run the rest of the code after the normal DOM handler.
94 // TODO(prem): Does this need debouncing?
95 setTimeout(async () => {
96 if (!forceTriggerCompletion) {
97 const newString = codeMirrorEditor.doc.getValue();
98 if (newString === oldString) {
99 // Cases like arrow keys, page up/down, etc. should fall here.
100 return;
101 }
102 }
103 const textModels: CodeMirror.Doc[] = [];
104 const isNotebook = codeMirrorEditor === this.notebookTracker.activeCell?.editor;
105 const widget = isNotebook
106 ? this.notebookTracker.currentWidget
107 : this.editorTracker.currentWidget;
108 if (isNotebook) {
109 const cells = this.notebookTracker.currentWidget?.content.widgets;
110 if (cells !== undefined) {
111 for (const cell of cells) {
112 textModels.push((cell.editor as CodeMirrorEditor).doc);
113 }
114 }
115 }
116 const context = widget !== null ? this.documentManager.contextForWidget(widget) : undefined;
117 const currentTextModel = codeMirrorEditor.doc;
118 await this.codeMirrorManager.triggerCompletion(
119 textModels,
120 currentTextModel,
121 new EditorOptions({
122 tabSize: BigInt(codeMirrorEditor.getOption('tabSize')),
123 insertSpaces: codeMirrorEditor.getOption('insertSpaces'),
124 }),
125 context?.localPath,
126 () => [
127 this.app.commands.addKeyBinding({
128 command: COMMAND_ACCEPT,
129 keys: ['Tab'],
130 selector: '.CodeMirror',
131 }),
132 this.app.commands.addKeyBinding({
133 command: COMMAND_DISMISS,
134 keys: ['Escape'],
135 selector: '.CodeMirror',
136 }),
137 ]

Callers

nothing calls this directly

Calls 2

beforeMainKeyHandlerMethod · 0.80
triggerCompletionMethod · 0.80

Tested by

no test coverage detected