vcs.showDiff {path?, staged?} (Mod+Alt+Shift+D) opens a "Diff: <name>"
tab in the editor area: @codemirror/merge (MIT, loaded lazily, 27 kB /
9.7 kB gzip), with the index (or HEAD for the staged view) read-only on
the left, line breaks normalised to LF, and the working copy on the right,
editable through its normal engine buffer. vcs.nextChange (Alt+Shift+])
and vcs.previousChange (Alt+Shift+[) move between chunks. Binary, too
large, failed and deleted files show a notice. Entry points: the Changes
window, a new project tree context menu (Open, Show Diff; right click or
Shift+F10) and the palette/menu. Colours come from the --lt-vcs-* tokens.
21 Vitest tests; parity docs updated (Git 6% -> 8%, est.).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
249 lines
5.8 KiB
Vue
249 lines
5.8 KiB
Vue
<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). Names are coloured by their
|
|
* Git status (`--lt-vcs-*`, M4.4). Diff tabs (M4.3, `vcs/diff/diff.ts`)
|
|
* follow the editor tabs; while one is active, no editor tab is marked
|
|
* active.
|
|
*/
|
|
import { X } from "@lucide/vue";
|
|
import { t } from "../../i18n";
|
|
import { useEditorStore } from "../../stores/editor";
|
|
import { useVcsStatusStore } from "../../stores/vcsStatus";
|
|
import { useDiffStore } from "../vcs/diff/diff";
|
|
|
|
const editor = useEditorStore();
|
|
const vcs = useVcsStatusStore();
|
|
const diff = useDiffStore();
|
|
|
|
/**
|
|
* Whether an editor tab is the active one.
|
|
*
|
|
* @param id - buffer id of the tab.
|
|
*/
|
|
function isActive(id: number): boolean {
|
|
return id === editor.activeId && !diff.visible;
|
|
}
|
|
|
|
/**
|
|
* Shows an editor tab (and hides an active diff).
|
|
*
|
|
* @param id - buffer id of the tab.
|
|
*/
|
|
function activateTab(id: number): void {
|
|
diff.deactivate();
|
|
editor.activate(id);
|
|
}
|
|
|
|
/**
|
|
* Closes a diff tab on a middle click.
|
|
*
|
|
* @param event - the auxiliary click.
|
|
* @param key - key of the diff tab.
|
|
*/
|
|
function onDiffAuxClick(event: MouseEvent, key: string): void {
|
|
if (event.button === 1) {
|
|
event.preventDefault();
|
|
diff.close(key);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 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) {
|
|
activateTab(next.id);
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<div
|
|
class="tabs"
|
|
role="tablist"
|
|
:aria-label="t('editor.tabs.label')"
|
|
data-test="editor-tabs"
|
|
@keydown="onKeydown"
|
|
>
|
|
<div
|
|
v-for="tab in editor.tabs"
|
|
:key="tab.id"
|
|
class="tabs__tab"
|
|
:class="{ 'tabs__tab--active': isActive(tab.id) }"
|
|
role="tab"
|
|
:tabindex="isActive(tab.id) ? 0 : -1"
|
|
:aria-selected="isActive(tab.id)"
|
|
:title="tab.path"
|
|
:data-id="tab.id"
|
|
data-test="editor-tab"
|
|
@click="activateTab(tab.id)"
|
|
@mousedown.middle.prevent
|
|
@auxclick="onAuxClick($event, tab.id)"
|
|
>
|
|
<span
|
|
class="tabs__name"
|
|
:class="vcs.colourOf(tab.path) ? `tabs__name--vcs-${vcs.colourOf(tab.path)}` : undefined"
|
|
:data-vcs="vcs.colourOf(tab.path) ?? undefined"
|
|
>{{ tab.name }}</span>
|
|
<span
|
|
v-if="tab.dirty"
|
|
class="tabs__dirty"
|
|
:aria-label="t('editor.tabs.unsaved')"
|
|
data-test="tab-dirty"
|
|
/>
|
|
<button
|
|
class="tabs__close"
|
|
type="button"
|
|
tabindex="-1"
|
|
:aria-label="t('editor.tabs.close', { name: tab.name })"
|
|
data-test="tab-close"
|
|
@click.stop="editor.requestClose(tab.id)"
|
|
>
|
|
<X :size="12" />
|
|
</button>
|
|
</div>
|
|
<div
|
|
v-for="tab in diff.tabs"
|
|
:key="tab.key"
|
|
class="tabs__tab"
|
|
:class="{ 'tabs__tab--active': tab.key === diff.activeKey }"
|
|
role="tab"
|
|
:tabindex="tab.key === diff.activeKey ? 0 : -1"
|
|
:aria-selected="tab.key === diff.activeKey"
|
|
:title="tab.path"
|
|
:data-key="tab.key"
|
|
data-test="diff-tab"
|
|
@click="diff.activate(tab.key)"
|
|
@mousedown.middle.prevent
|
|
@auxclick="onDiffAuxClick($event, tab.key)"
|
|
>
|
|
<span class="tabs__name">{{ tab.staged ? t("vcs.diff.tabTitleStaged", { name: tab.name }) : t("vcs.diff.tabTitle", { name: tab.name }) }}</span>
|
|
<button
|
|
class="tabs__close"
|
|
type="button"
|
|
tabindex="-1"
|
|
:aria-label="t('vcs.diff.closeTab', { name: tab.name })"
|
|
data-test="diff-tab-close"
|
|
@click.stop="diff.close(tab.key)"
|
|
>
|
|
<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);
|
|
border-bottom-color: var(--lt-accent);
|
|
}
|
|
|
|
.tabs__tab:focus-visible {
|
|
outline: 1px solid var(--lt-accent);
|
|
outline-offset: -1px;
|
|
}
|
|
|
|
.tabs__name--vcs-added {
|
|
color: var(--lt-vcs-added);
|
|
}
|
|
|
|
.tabs__name--vcs-modified {
|
|
color: var(--lt-vcs-modified);
|
|
}
|
|
|
|
.tabs__name--vcs-deleted {
|
|
color: var(--lt-vcs-deleted);
|
|
}
|
|
|
|
.tabs__name--vcs-untracked {
|
|
color: var(--lt-vcs-untracked);
|
|
}
|
|
|
|
.tabs__name--vcs-ignored {
|
|
color: var(--lt-vcs-ignored);
|
|
}
|
|
|
|
.tabs__name--vcs-conflicted {
|
|
color: var(--lt-vcs-conflicted);
|
|
}
|
|
|
|
.tabs__dirty {
|
|
width: 7px;
|
|
height: 7px;
|
|
border-radius: 50%;
|
|
background: var(--lt-tab-modified);
|
|
}
|
|
|
|
.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>
|