@jupyter-lsp/code-jumpers
Version:
Implementation underlying the jump to definition functionality in JupyterLab-LSP
22 lines (18 loc) • 591 B
text/typescript
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
import { Notebook } from '@jupyterlab/notebook';
/**
* Ensure that the notebook has proper focus.
*/
function _ensureFocus(notebook: Notebook, force = false): void {
let activeCell = notebook.activeCell;
if (notebook.mode === 'edit' && activeCell && activeCell.editor) {
if (!activeCell.editor.hasFocus()) {
activeCell.editor.focus();
}
}
if (force && !notebook.node.contains(document.activeElement)) {
notebook.node.focus();
}
}
export { _ensureFocus };