Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions dbml-homepage/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6373,9 +6373,9 @@ immer@^9.0.7:
integrity sha512-bc4NBHqOqSfRW7POMkHd51LvClaeMXpm8dx0e8oE2GORbq5aRK7Bxl4FyzVLdGtLmvLKL7BTDBG5ACQm4HWjTA==

immutable@^4.0.0:
version "4.3.5"
resolved "https://registry.yarnpkg.com/immutable/-/immutable-4.3.5.tgz#f8b436e66d59f99760dc577f5c99a4fd2a5cc5a0"
integrity sha512-8eabxkth9gZatlwl5TBuJnCsoTADlL6ftEr7A4qgdaTsPyreilDSnUk57SO+jfKcNtxPa22U5KK6DSeAYhpBJw==
version "4.3.8"
resolved "https://registry.yarnpkg.com/immutable/-/immutable-4.3.8.tgz#02d183c7727fb2bb1d5d0380da0d779dce9296a7"
integrity sha512-d/Ld9aLbKpNwyl0KiM2CT1WYvkitQ1TSvmRtkcV8FKStiDoA7Slzgjmb/1G2yhKM1p0XeNOieaTbFZmU1d3Xuw==

import-fresh@^3.1.0, import-fresh@^3.3.0:
version "3.3.0"
Expand Down
47 changes: 29 additions & 18 deletions dbml-playground/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
<EditorPane
v-model="project.currentContent"
@editor-mounted="onDbmlEditorMounted"
@cursor-move="(pos) => { dbmlCursorPos.value = pos }"
@cursor-move="onEditorCursorMove"
/>
</template>
<template #panel-2>
Expand Down Expand Up @@ -221,6 +221,13 @@ function onKeyDown (e: KeyboardEvent) {
}
}

function onEditorCursorMove (pos: {
line: number;
column: number;
}) {
dbmlCursorPos.value = pos;
}

onMounted(() => window.addEventListener('keydown', onKeyDown));
onBeforeUnmount(() => window.removeEventListener('keydown', onKeyDown));

Expand All @@ -235,13 +242,12 @@ const onDbmlEditorMounted = (editor: monaco.editor.IStandaloneCodeEditor) => {
dbmlEditorRef.value = editor;
setupDbmlServices(parser.compiler);

// Monaco's StandaloneCodeEditorService.findModel returns null when the target URI
// doesn't match the current model -> cross-file navigation silently fails.
// registerCodeEditorOpenHandler prepends a handler that runs before the built-in one.
// We handle cross-file navigation by switching the active project file first.
const svc = (editor as any)._codeEditorService;
svc?.registerCodeEditorOpenHandler?.(async (input: { resource?: monaco.Uri;
options?: { selection?: monaco.IRange }; }) => {
// This ensures the text model exists before switching to that model
const codeEditorService = (editor as any)._codeEditorService;
codeEditorService?.registerCodeEditorOpenHandler?.(async (input: {
resource?: monaco.Uri;
options?: { selection?: monaco.IRange };
}) => {
const resource = input?.resource;
if (!resource) return null;

Expand All @@ -252,22 +258,27 @@ const onDbmlEditorMounted = (editor: monaco.editor.IStandaloneCodeEditor) => {

project.setCurrentFile(targetFilepath.absolute);
// Wait for the filepath watcher -> createModel -> setModel chain.
// onDidChangeModel fires synchronously when setModel is called, which is
// more reliable than nextTick because it doesn't depend on Vue flush timing.
// onDidChangeModel fires synchronously when setModel is called
await new Promise<void>((resolve) => {
const d = editor.onDidChangeModel(() => { d.dispose(); resolve(); });
const d = editor.onDidChangeModel(() => {
d.dispose();
resolve();
});
setTimeout(resolve, 500);
});

const sel = input.options?.selection;
if (sel) {
if (typeof sel.endLineNumber === 'number' && typeof sel.endColumn === 'number') {
editor.setSelection(sel);
editor.revealRangeInCenter(sel);
const selection = input.options?.selection;
if (selection) {
if (
typeof selection.endLineNumber === 'number'
&& typeof selection.endColumn === 'number'
) {
editor.setSelection(selection);
editor.revealRangeInCenter(selection);
} else {
const pos = {
lineNumber: sel.startLineNumber,
column: sel.startColumn,
lineNumber: selection.startLineNumber,
column: selection.startColumn,
};
editor.setPosition(pos);
editor.revealPositionInCenter(pos);
Expand Down
3 changes: 1 addition & 2 deletions dbml-playground/src/components/editor/useVimController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ export function useVimController (editor: ShallowRef<monaco.editor.IStandaloneCo
});
modeStatus.value = 'NORMAL';

vimAdapter.on('vim-mode-change', (mode: { mode: string;
subMode?: string; }) => {
vimAdapter.on('vim-mode-change', (mode: { mode: string }) => {
modeStatus.value = (mode.mode || 'NORMAL').toUpperCase();
});
} catch (error) {
Expand Down
12 changes: 8 additions & 4 deletions dbml-playground/src/components/panes/output/OutputPane.vue
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,12 @@ onBeforeUnmount(() => {
navDecorations?.clear();
});

function navigateTo (range: { startLineNumber: number;
function navigateTo (range: {
startLineNumber: number;
startColumn: number;
endLineNumber: number;
endColumn: number; }) {
endColumn: number;
}) {
const editor = dbmlEditorRef?.value;
if (!editor) return;
try {
Expand Down Expand Up @@ -294,10 +296,12 @@ function onDiagnosticClick (diag: {
}

// Navigate to a declaration that may be in a different file.
async function navigateToDeclaration (targetFilepath: string | null, range: { startLineNumber: number;
async function navigateToDeclaration (targetFilepath: string | null, range: {
startLineNumber: number;
startColumn: number;
endLineNumber: number;
endColumn: number; }) {
endColumn: number;
}) {
const editor = dbmlEditorRef?.value;
if (!editor) return;
if (targetFilepath && new Filepath(targetFilepath).intern() !== new Filepath(project.currentFile).intern()) {
Expand Down
Loading