From ce076b1f74173703022daf02df1a182dd0aba464 Mon Sep 17 00:00:00 2001 From: Rob Gordon Date: Tue, 2 Jan 2024 11:33:00 -0500 Subject: [PATCH] Toggle tab if necessary before focusing --- app/src/lib/useEditorStore.ts | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/app/src/lib/useEditorStore.ts b/app/src/lib/useEditorStore.ts index dc89a03f7..7a1badce5 100644 --- a/app/src/lib/useEditorStore.ts +++ b/app/src/lib/useEditorStore.ts @@ -1,5 +1,6 @@ import type { editor } from "monaco-editor"; import { create } from "zustand"; +import { useMobileStore } from "./useMobileStore"; /** * Stores client-side state related to the editor. @@ -34,8 +35,19 @@ export function updateModelMarkers() { * Focuses the editor. Then moves the cursor to the given line. */ export function moveCursorToLine(line: number) { - const { editor } = useEditorStore.getState(); - if (!editor) return; - editor.focus(); - editor.setPosition({ lineNumber: line, column: Infinity }); + // We toggle the tab just in case we're in mobile view + const { tab, toggleTab } = useMobileStore.getState(); + if (tab === "graph") { + toggleTab(); + requestAnimationFrame(focus); + } else { + focus(); + } + + function focus() { + const { editor } = useEditorStore.getState(); + if (!editor) return; + editor.focus(); + editor.setPosition({ lineNumber: line, column: Infinity }); + } }