M4.3: side-by-side diff viewer with next/previous change

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>
This commit is contained in:
danny 2026-10-26 17:23:52 +01:00
parent 468b9928a7
commit 8360ffc2e2
23 changed files with 1836 additions and 24 deletions

View file

@ -5,15 +5,51 @@
* 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).
* 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.
@ -42,7 +78,7 @@ function onKeydown(event: KeyboardEvent): void {
event.preventDefault();
const next = editor.tabs[(index + step + editor.tabs.length) % editor.tabs.length];
if (next) {
editor.activate(next.id);
activateTab(next.id);
}
}
</script>
@ -59,14 +95,14 @@ function onKeydown(event: KeyboardEvent): void {
v-for="tab in editor.tabs"
:key="tab.id"
class="tabs__tab"
:class="{ 'tabs__tab--active': tab.id === editor.activeId }"
:class="{ 'tabs__tab--active': isActive(tab.id) }"
role="tab"
:tabindex="tab.id === editor.activeId ? 0 : -1"
:aria-selected="tab.id === editor.activeId"
:tabindex="isActive(tab.id) ? 0 : -1"
:aria-selected="isActive(tab.id)"
:title="tab.path"
:data-id="tab.id"
data-test="editor-tab"
@click="editor.activate(tab.id)"
@click="activateTab(tab.id)"
@mousedown.middle.prevent
@auxclick="onAuxClick($event, tab.id)"
>
@ -92,6 +128,33 @@ function onKeydown(event: KeyboardEvent): void {
<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>