(editor: TextEditor)
| 39 | } |
| 40 | |
| 41 | export async function focusEditor(editor: TextEditor) { |
| 42 | if (editor.viewColumn != null) { |
| 43 | await commands.executeCommand(columnFocusCommands[editor.viewColumn]); |
| 44 | } else { |
| 45 | // If the view column is null we see if it's a notebook and try to see if we |
| 46 | // can just move around in the notebook to focus the correct editor |
| 47 | const activeTextEditor = window.activeTextEditor; |
| 48 | |
| 49 | if (activeTextEditor == null) { |
| 50 | return; |
| 51 | } |
| 52 | |
| 53 | const editorNotebook = getNotebookFromCellDocument(editor.document); |
| 54 | const activeEditorNotebook = getNotebookFromCellDocument( |
| 55 | activeTextEditor.document |
| 56 | ); |
| 57 | |
| 58 | if ( |
| 59 | editorNotebook == null || |
| 60 | activeEditorNotebook == null || |
| 61 | editorNotebook !== activeEditorNotebook |
| 62 | ) { |
| 63 | return; |
| 64 | } |
| 65 | |
| 66 | const editorIndex = getCellIndex(editorNotebook, editor.document); |
| 67 | const activeEditorIndex = getCellIndex( |
| 68 | editorNotebook, |
| 69 | activeTextEditor.document |
| 70 | ); |
| 71 | |
| 72 | if (editorIndex === -1 || activeEditorIndex === -1) { |
| 73 | throw new Error( |
| 74 | "Couldn't find editor corresponding to given cell in the expected notebook" |
| 75 | ); |
| 76 | } |
| 77 | |
| 78 | const cellOffset = editorIndex - activeEditorIndex; |
| 79 | |
| 80 | const command = |
| 81 | cellOffset < 0 |
| 82 | ? "notebook.focusPreviousEditor" |
| 83 | : "notebook.focusNextEditor"; |
| 84 | |
| 85 | // This is a hack. We just repeatedly issued the command to move upwards or |
| 86 | // downwards a cell to get to the right cell |
| 87 | for (const index of range(Math.abs(cellOffset))) { |
| 88 | await commands.executeCommand(command); |
| 89 | } |
| 90 | } |
| 91 | } |
no test coverage detected