Skip to content

Commit

Permalink
Toggle tab if necessary before focusing
Browse files Browse the repository at this point in the history
  • Loading branch information
rob-gordon committed Jan 2, 2024
1 parent 434d081 commit ce076b1
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions app/src/lib/useEditorStore.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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 });
}
}

0 comments on commit ce076b1

Please sign in to comment.