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
154
ui/src/components/editor/EditorTabs.vue
Normal file
154
ui/src/components/editor/EditorTabs.vue
Normal file
|
|
@ -0,0 +1,154 @@
|
|||
<script setup lang="ts">
|
||||
/**
|
||||
* The tab bar of the editor area, following the WAI-ARIA tabs pattern.
|
||||
*
|
||||
* A click activates a tab, a middle click or the close button closes it,
|
||||
* Left/Right move between tabs. A dot marks unsaved changes. Closing a
|
||||
* dirty tab asks first (see the editor store).
|
||||
*/
|
||||
import { X } from "@lucide/vue";
|
||||
import { useEditorStore } from "../../stores/editor";
|
||||
|
||||
const editor = useEditorStore();
|
||||
|
||||
/**
|
||||
* Closes a tab on a middle click.
|
||||
*
|
||||
* @param event - the auxiliary click.
|
||||
* @param id - buffer id of the tab.
|
||||
*/
|
||||
function onAuxClick(event: MouseEvent, id: number): void {
|
||||
if (event.button === 1) {
|
||||
event.preventDefault();
|
||||
void editor.requestClose(id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Keyboard navigation between tabs.
|
||||
*
|
||||
* @param event - the key event on the tab list.
|
||||
*/
|
||||
function onKeydown(event: KeyboardEvent): void {
|
||||
const index = editor.tabs.findIndex((t) => t.id === editor.activeId);
|
||||
const step = event.key === "ArrowRight" ? 1 : event.key === "ArrowLeft" ? -1 : 0;
|
||||
if (step === 0 || editor.tabs.length === 0) {
|
||||
return;
|
||||
}
|
||||
event.preventDefault();
|
||||
const next = editor.tabs[(index + step + editor.tabs.length) % editor.tabs.length];
|
||||
if (next) {
|
||||
editor.activate(next.id);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
class="tabs"
|
||||
role="tablist"
|
||||
aria-label="Editor tabs"
|
||||
data-test="editor-tabs"
|
||||
@keydown="onKeydown"
|
||||
>
|
||||
<div
|
||||
v-for="tab in editor.tabs"
|
||||
:key="tab.id"
|
||||
class="tabs__tab"
|
||||
:class="{ 'tabs__tab--active': tab.id === editor.activeId }"
|
||||
role="tab"
|
||||
:tabindex="tab.id === editor.activeId ? 0 : -1"
|
||||
:aria-selected="tab.id === editor.activeId"
|
||||
:title="tab.path"
|
||||
:data-id="tab.id"
|
||||
data-test="editor-tab"
|
||||
@click="editor.activate(tab.id)"
|
||||
@mousedown.middle.prevent
|
||||
@auxclick="onAuxClick($event, tab.id)"
|
||||
>
|
||||
<span class="tabs__name">{{ tab.name }}</span>
|
||||
<span
|
||||
v-if="tab.dirty"
|
||||
class="tabs__dirty"
|
||||
aria-label="unsaved changes"
|
||||
data-test="tab-dirty"
|
||||
/>
|
||||
<button
|
||||
class="tabs__close"
|
||||
type="button"
|
||||
tabindex="-1"
|
||||
:aria-label="`Close ${tab.name}`"
|
||||
data-test="tab-close"
|
||||
@click.stop="editor.requestClose(tab.id)"
|
||||
>
|
||||
<X :size="12" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.tabs {
|
||||
display: flex;
|
||||
overflow-x: auto;
|
||||
flex-shrink: 0;
|
||||
background: var(--lt-bg);
|
||||
border-bottom: 1px solid var(--lt-border);
|
||||
scrollbar-width: thin;
|
||||
}
|
||||
|
||||
.tabs__tab {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
padding: 0 6px 0 12px;
|
||||
height: 30px;
|
||||
flex-shrink: 0;
|
||||
color: var(--lt-fg-muted);
|
||||
border-right: 1px solid var(--lt-border);
|
||||
border-bottom: 2px solid transparent;
|
||||
cursor: default;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.tabs__tab:hover {
|
||||
color: var(--lt-fg);
|
||||
}
|
||||
|
||||
.tabs__tab--active {
|
||||
color: var(--lt-fg);
|
||||
background: var(--lt-tab-active-bg, var(--lt-editor-bg));
|
||||
border-bottom-color: var(--lt-accent);
|
||||
}
|
||||
|
||||
.tabs__tab:focus-visible {
|
||||
outline: 1px solid var(--lt-accent);
|
||||
outline-offset: -1px;
|
||||
}
|
||||
|
||||
.tabs__dirty {
|
||||
width: 7px;
|
||||
height: 7px;
|
||||
border-radius: 50%;
|
||||
background: var(--lt-tab-modified, var(--lt-accent));
|
||||
}
|
||||
|
||||
.tabs__close {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
padding: 0;
|
||||
border: none;
|
||||
border-radius: 3px;
|
||||
background: transparent;
|
||||
color: inherit;
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
.tabs__close:hover {
|
||||
opacity: 1;
|
||||
background: var(--lt-border);
|
||||
}
|
||||
</style>
|
||||
Loading…
Add table
Add a link
Reference in a new issue