Skip to content

Commit

Permalink
fix: set initial cursor for creator drawer
Browse files Browse the repository at this point in the history
  • Loading branch information
macjuul committed Apr 26, 2024
1 parent 3a60313 commit 72f871e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/components/CodeEditor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface CodeEditorProps extends BoxProps {
extensions?: Extension[];
readOnly?: boolean;
autoFocus?: boolean;
onMount?: (editor: EditorView) => void;
onChange?: (value: string) => void;
}

Expand All @@ -29,6 +30,7 @@ export function CodeEditor(props: CodeEditorProps) {
className,
readOnly,
autoFocus,
onMount,
...rest
} = props;

Expand Down Expand Up @@ -76,6 +78,8 @@ export function CodeEditor(props: CodeEditorProps) {
}, 50);
}

onMount?.(editor);

return () => {
editor.destroy();
};
Expand Down
8 changes: 7 additions & 1 deletion src/views/explorer/CreatorDrawer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { RecordId, Table } from "surrealdb.js";
import { useDebouncedParsedObject } from "~/hooks/debounce";
import { surqlLinting } from "~/util/editor/extensions";
import { surrealql } from "codemirror-surrealql";
import { EditorView } from "@codemirror/view";

export interface CreatorDrawerProps {
opened: boolean;
Expand Down Expand Up @@ -49,6 +50,10 @@ export function CreatorDrawer({ opened, table, onClose }: CreatorDrawerProps) {
RecordsChangedEvent.dispatch(null);
});

const setCursor = useStable((editor: EditorView) => {
editor.dispatch({selection: {anchor: 6, head: 6}});
});

useLayoutEffect(() => {
if (opened) {
setRecordTable(table);
Expand Down Expand Up @@ -128,8 +133,9 @@ export function CreatorDrawer({ opened, table, onClose }: CreatorDrawerProps) {
onChange={setRecordBody}
extensions={[
surrealql(),
surqlLinting(),
surqlLinting()
]}
onMount={setCursor}
/>
</Paper>
</Stack>
Expand Down

0 comments on commit 72f871e

Please sign in to comment.