| 28 | } |
| 29 | |
| 30 | export async function getAndUpdateModeHandler( |
| 31 | forceSyncAndUpdate = false, |
| 32 | ): Promise<ModeHandler | undefined> { |
| 33 | const activeTextEditor = vscode.window.activeTextEditor; |
| 34 | if (activeTextEditor === undefined || activeTextEditor.document.isClosed) { |
| 35 | return undefined; |
| 36 | } |
| 37 | |
| 38 | const [curHandler, isNew] = await ModeHandlerMap.getOrCreate(activeTextEditor); |
| 39 | if (isNew) { |
| 40 | extensionContext.subscriptions.push(curHandler); |
| 41 | } |
| 42 | |
| 43 | curHandler.vimState.editor = activeTextEditor; |
| 44 | |
| 45 | if ( |
| 46 | forceSyncAndUpdate || |
| 47 | !previousActiveEditorUri || |
| 48 | previousActiveEditorUri !== activeTextEditor.document.uri |
| 49 | ) { |
| 50 | // We sync the cursors here because ModeHandler is specific to a document, not an editor, so we |
| 51 | // need to update our representation of the cursors when switching between editors for the same document. |
| 52 | // This will be unnecessary once #4889 is fixed. |
| 53 | curHandler.syncCursors(); |
| 54 | curHandler.updateView({ drawSelection: false, revealRange: false }); |
| 55 | } |
| 56 | |
| 57 | previousActiveEditorUri = activeTextEditor.document.uri; |
| 58 | |
| 59 | if (curHandler.focusChanged) { |
| 60 | curHandler.focusChanged = false; |
| 61 | |
| 62 | if (previousActiveEditorUri) { |
| 63 | const prevHandler = ModeHandlerMap.get(previousActiveEditorUri); |
| 64 | prevHandler!.focusChanged = true; |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | return curHandler; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Loads and validates the user's configuration |