M1.6: tabs and CodeMirror editor
- Editor area with tab bar, CodeMirror 6 view, close question and notices (ui/src/components/editor/, ui/src/stores/editor.ts), mounted in App.vue; the project tree opens files through the editor store. - BufferSync: local edits to buffer.edit against the confirmed version, one call in flight, resync on stale_version or newer bufferChanged with rebase of unsent changes; EngineText maps CodeMirror positions to engine UTF-16 offsets for CRLF text. - Save, save all and close from engine default shortcuts via listCommands. - Dirty marker, Save / Don't Save / Cancel, non-blocking notice when a dirty file changes or disappears on disk. - Vitest: keystroke bursts with stale versions and remote edits (LF and CRLF), mapping, store and component tests against a fake engine. - Progress docs: Editor core 8% (est.), depth ~1.4%, G2, ui-parity tabs, M1 row, architecture, README status. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
0fb7e33fc7
commit
9fa6028335
25 changed files with 2958 additions and 22 deletions
158
ui/src/components/editor/EditorArea.vue
Normal file
158
ui/src/components/editor/EditorArea.vue
Normal file
|
|
@ -0,0 +1,158 @@
|
|||
<script setup lang="ts">
|
||||
/**
|
||||
* The editor area: tab bar, a notice line for the active tab, the editor
|
||||
* and the close question. Without open tabs it shows the default slot.
|
||||
*
|
||||
* Shortcuts come from the engine's command specs (see `shortcuts.ts`); the
|
||||
* area listens on the window in the capture phase so they also work while
|
||||
* CodeMirror has the focus.
|
||||
*/
|
||||
import { onBeforeUnmount, onMounted } from "vue";
|
||||
import { useEditorStore } from "../../stores/editor";
|
||||
import ClosePrompt from "./ClosePrompt.vue";
|
||||
import CodeEditor from "./CodeEditor.vue";
|
||||
import EditorTabs from "./EditorTabs.vue";
|
||||
import { commandFor, loadEditorKeymap, type EditorKeymap } from "./shortcuts";
|
||||
|
||||
const editor = useEditorStore();
|
||||
|
||||
/** Keymap loaded from the engine, empty until loaded. */
|
||||
let keymap: EditorKeymap = [];
|
||||
|
||||
/**
|
||||
* Runs the editor command bound to a key press.
|
||||
*
|
||||
* @param event - a key press anywhere in the window.
|
||||
*/
|
||||
function onKeydown(event: KeyboardEvent): void {
|
||||
const command = commandFor(keymap, event);
|
||||
if (command === null) {
|
||||
return;
|
||||
}
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
switch (command) {
|
||||
case "file.save":
|
||||
void editor.save();
|
||||
break;
|
||||
case "file.saveAll":
|
||||
void editor.saveAll();
|
||||
break;
|
||||
case "buffer.close":
|
||||
void editor.requestClose();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
editor.start();
|
||||
window.addEventListener("keydown", onKeydown, true);
|
||||
void loadEditorKeymap().then((result) => {
|
||||
if (result.ok) {
|
||||
keymap = result.value;
|
||||
} else {
|
||||
editor.lastError = result.error;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
window.removeEventListener("keydown", onKeydown, true);
|
||||
editor.stop();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
class="editor-area"
|
||||
data-test="editor-area"
|
||||
>
|
||||
<template v-if="editor.tabs.length > 0">
|
||||
<EditorTabs />
|
||||
<div
|
||||
v-if="editor.activeTab?.notice"
|
||||
class="editor-area__notice"
|
||||
:class="{ 'editor-area__notice--error': editor.activeTab.notice.kind === 'error' }"
|
||||
role="status"
|
||||
data-test="editor-notice"
|
||||
>
|
||||
<span>{{ editor.activeTab.notice.message }}</span>
|
||||
<button
|
||||
type="button"
|
||||
class="editor-area__dismiss"
|
||||
data-test="notice-dismiss"
|
||||
@click="editor.dismissNotice(editor.activeTab.id)"
|
||||
>
|
||||
Dismiss
|
||||
</button>
|
||||
</div>
|
||||
<CodeEditor />
|
||||
</template>
|
||||
<div
|
||||
v-else
|
||||
class="editor-area__empty"
|
||||
>
|
||||
<slot />
|
||||
</div>
|
||||
<div
|
||||
v-if="editor.lastError"
|
||||
class="editor-area__notice editor-area__notice--error"
|
||||
role="alert"
|
||||
data-test="editor-error"
|
||||
>
|
||||
<span>{{ editor.lastError.message }}</span>
|
||||
<button
|
||||
type="button"
|
||||
class="editor-area__dismiss"
|
||||
@click="editor.lastError = null"
|
||||
>
|
||||
Dismiss
|
||||
</button>
|
||||
</div>
|
||||
<ClosePrompt />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.editor-area {
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex: 1;
|
||||
align-self: stretch;
|
||||
min-width: 0;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.editor-area__empty {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.editor-area__notice {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 4px 12px;
|
||||
flex-shrink: 0;
|
||||
color: var(--lt-fg);
|
||||
background: var(--lt-notice-bg, color-mix(in srgb, var(--lt-accent) 15%, var(--lt-bg)));
|
||||
border-bottom: 1px solid var(--lt-border);
|
||||
}
|
||||
|
||||
.editor-area__notice--error {
|
||||
background: color-mix(in srgb, var(--lt-error) 15%, var(--lt-bg));
|
||||
}
|
||||
|
||||
.editor-area__dismiss {
|
||||
margin-left: auto;
|
||||
padding: 0 8px;
|
||||
font: inherit;
|
||||
color: var(--lt-fg);
|
||||
background: transparent;
|
||||
border: 1px solid var(--lt-border);
|
||||
border-radius: 3px;
|
||||
}
|
||||
</style>
|
||||
Loading…
Add table
Add a link
Reference in a new issue