- crates/vcs chunk.rs: chunks of a file (buffer text vs index, HEAD vs
index), a minimal patch applied with git apply --cached, revert as a
byte edit; token refusal when buffer, index or HEAD changed; CRLF
(autocrlf and stored), no final newline, BOM, staged renames, first
commit; binary and untracked refused. Real-git tests + property test.
- engine: git.chunks, git.stageChunk, git.unstageChunk, git.revertChunk
(revert edits the buffer under the lock, undoable in the editor);
cmd:
:start_then; git.lineChanges shares the vcs line diff.
- UI: chunk popup on a gutter marker click (Stage / Unstage / Revert /
Previous / Next), hollow staged markers, vcs.showChunk, diff viewer
hint, "partly staged" badge in the Changes window.
- Docs: G8 row, Git parity row evidence, ui-parity, architecture.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
447 lines
15 KiB
Vue
447 lines
15 KiB
Vue
<script setup lang="ts">
|
|
/**
|
|
* Layout of the main window: the left tool-window stripe, the left tool
|
|
* window, the editor area in the middle, the bottom panel under both
|
|
* (M2.4) and the status bar along the bottom.
|
|
*
|
|
* The editor area is a slot so the editor (M1.6) can replace the
|
|
* placeholder without touching the layout.
|
|
*
|
|
* The left stripe (M2.7) is a vertical tab list with Project and
|
|
* Structure. The left tool window shows one of them; clicking the shown
|
|
* one's tab hides the window, clicking the other switches to it. Both stay
|
|
* mounted while the window is open, so switching keeps their state. The
|
|
* layout supplies the UI commands `view.toggleProjectTree` (`Mod+1`) and
|
|
* `view.toggleStructure` (`Mod+2`): each shows its tool window, or hides
|
|
* the left window when that tool window is already shown.
|
|
*
|
|
* The bottom panel ({@link BottomPanel}) holds the Find, Terminal and
|
|
* Problems tool windows, as tabs in its header while more than one is
|
|
* shown. Find appears with the UI command `find.open` (`Mod+Alt+F`),
|
|
* Terminal with `terminal.open` (`Mod+Shift+T`, M3.6), Problems with
|
|
* `problems.open` (`Mod+Alt+P`, M3.3); all are supplied here so they work
|
|
* before the panel exists, and each makes its tool window the active tab.
|
|
* The panel collapses to its header; closing it hides the active tool
|
|
* window (another shown one becomes active). The Find store keeps the
|
|
* results, the Terminal store the running terminals and the Problems store
|
|
* the diagnostics while they are hidden. The References tab (M3.5) shows
|
|
* when Find References runs (`lsp.references`); the nav store keeps its
|
|
* results. The Changes tab (M4.2) appears with `vcs.openChanges`
|
|
* (`Mod+Alt+Shift+G`) and `vcs.commit` (`Mod+Alt+Shift+M`, which also
|
|
* focuses the commit message box); `vcs.refresh` re-reads the Git status.
|
|
* Its store reads the status from the start, so it is current when the
|
|
* tab opens. The Log tab (M4.6) appears with `vcs.showLog` and with
|
|
* `vcs.showHistory {path?}` (the history of a file or folder; without a
|
|
* path, of the active editor tab's file); neither has a default shortcut.
|
|
* `vcs.showCommit {hash}` (M4.7) shows the Log with that commit selected
|
|
* (a click on a blame annotation); `vcs.toggleBlame {path?}` shows or
|
|
* hides the blame annotations of a file (default: the active tab's, once
|
|
* tabs for buffers just opened are adopted). `vcs.showChunk` (C8 C3)
|
|
* opens the chunk popup at the caret line of the editor shown last. No
|
|
* default shortcuts.
|
|
*
|
|
* A slim header bar along the top (M3.9) holds the app menu
|
|
* ({@link AppMenu}); its `header` slot can replace it.
|
|
*/
|
|
import { FolderTree, ListTree } from "@lucide/vue";
|
|
import { computed, onBeforeUnmount, onMounted, ref } from "vue";
|
|
import { useCommandsStore } from "../../commands/store";
|
|
import { t } from "../../i18n";
|
|
import { useFindStore } from "../../stores/find";
|
|
import { useTerminalStore } from "../../stores/terminal";
|
|
import FindToolWindow from "../find/FindToolWindow.vue";
|
|
import TerminalToolWindow from "../terminal/TerminalToolWindow.vue";
|
|
import ProblemsToolWindow from "../problems/ProblemsToolWindow.vue";
|
|
import { useProblemsStore } from "../problems/problems";
|
|
import ReferencesToolWindow from "../editor/nav/ReferencesToolWindow.vue";
|
|
import { useNavStore } from "../editor/nav/nav";
|
|
import ChangesToolWindow from "../vcs/changes/ChangesToolWindow.vue";
|
|
import { useChangesStore } from "../vcs/changes/changes";
|
|
import LogToolWindow from "../vcs/log/LogToolWindow.vue";
|
|
import { SHOW_HISTORY_COMMAND, SHOW_LOG_COMMAND, useLogStore } from "../vcs/log/log";
|
|
import StashDialog from "../vcs/stash/StashDialog.vue";
|
|
import { SHOW_COMMIT_COMMAND, TOGGLE_BLAME_COMMAND, setCommitOpener, toggleBlame } from "../editor/blame";
|
|
import { SHOW_CHUNK_COMMAND, openChunkPopup } from "../editor/chunkPopup";
|
|
import { activeView } from "../editor/nav/navExtension";
|
|
import { useEditorStore } from "../../stores/editor";
|
|
import { useProjectStore } from "../../stores/project";
|
|
import ProjectToolWindow from "../project/ProjectToolWindow.vue";
|
|
import StatusBar from "../StatusBar.vue";
|
|
import StructureToolWindow from "../structure/StructureToolWindow.vue";
|
|
import AppMenu from "../menu/AppMenu.vue";
|
|
import BottomPanel from "./BottomPanel.vue";
|
|
import ToolWindow from "./ToolWindow.vue";
|
|
|
|
/** Width of the left tool window in CSS pixels. */
|
|
const leftWidth = ref(260);
|
|
/** Whether the left tool window is shown. */
|
|
const leftOpen = ref(true);
|
|
/** Height of the bottom panel's content in CSS pixels. */
|
|
const bottomHeight = ref(240);
|
|
|
|
/** Tool windows of the left side. */
|
|
type LeftTool = "project" | "structure";
|
|
/** The left tool window shown while {@link leftOpen} is set. */
|
|
const leftTool = ref<LeftTool>("project");
|
|
/** Stripe tabs in display order: id, title and icon. */
|
|
const leftTools = computed(() => [
|
|
{ id: "project" as const, title: t("project.toolWindow.title"), icon: FolderTree },
|
|
{ id: "structure" as const, title: t("structure.toolWindow.title"), icon: ListTree },
|
|
]);
|
|
/** Title of the shown left tool window. */
|
|
const leftTitle = computed(() => leftTools.value.find((tool) => tool.id === leftTool.value)?.title ?? "");
|
|
|
|
/**
|
|
* Shows a left tool window, or hides the left window when it is already
|
|
* shown.
|
|
*
|
|
* @param tool - the tool window.
|
|
*/
|
|
function toggleLeft(tool: LeftTool): void {
|
|
if (leftOpen.value && leftTool.value === tool) {
|
|
leftOpen.value = false;
|
|
return;
|
|
}
|
|
leftTool.value = tool;
|
|
leftOpen.value = true;
|
|
}
|
|
|
|
const commands = useCommandsStore();
|
|
const find = useFindStore();
|
|
const terminal = useTerminalStore();
|
|
const problems = useProblemsStore();
|
|
const nav = useNavStore();
|
|
const changes = useChangesStore();
|
|
const vcsLog = useLogStore();
|
|
const editor = useEditorStore();
|
|
const project = useProjectStore();
|
|
|
|
/** Tool windows of the bottom panel. */
|
|
type BottomTool = "find" | "terminal" | "problems" | "references" | "changes" | "log";
|
|
/** The bottom tool window last chosen. */
|
|
const bottomTool = ref<BottomTool>("find");
|
|
/** Bottom tool windows that are shown, in tab order. */
|
|
const bottomTools = computed(() => {
|
|
const tools: { id: BottomTool; title: string }[] = [];
|
|
if (find.visible) tools.push({ id: "find", title: t("find.toolWindow.title") });
|
|
if (terminal.visible) tools.push({ id: "terminal", title: t("terminal.toolWindow.title") });
|
|
if (problems.visible) tools.push({ id: "problems", title: t("problems.toolWindow.title") });
|
|
if (nav.visible) tools.push({ id: "references", title: t("nav.references.title") });
|
|
if (changes.visible) tools.push({ id: "changes", title: t("vcs.changes.toolWindow.title") });
|
|
if (vcsLog.visible) tools.push({ id: "log", title: t("vcs.log.toolWindow.title") });
|
|
return tools;
|
|
});
|
|
/** The active bottom tool window: the chosen one if shown, else the first. */
|
|
const bottomActive = computed<BottomTool | null>(() => {
|
|
const tools = bottomTools.value;
|
|
return tools.some((tool) => tool.id === bottomTool.value) ? bottomTool.value : (tools[0]?.id ?? null);
|
|
});
|
|
/** The store of the active bottom tool window. */
|
|
const bottomStore = computed(() =>
|
|
bottomActive.value === "terminal"
|
|
? terminal
|
|
: bottomActive.value === "problems"
|
|
? problems
|
|
: bottomActive.value === "references"
|
|
? nav
|
|
: bottomActive.value === "changes"
|
|
? changes
|
|
: bottomActive.value === "log"
|
|
? vcsLog
|
|
: find,
|
|
);
|
|
/** Expansion of the panel, kept per tool window by its store. */
|
|
const bottomOpen = computed({
|
|
get: () => bottomStore.value.expanded,
|
|
set: (open: boolean) => {
|
|
bottomStore.value.expanded = open;
|
|
},
|
|
});
|
|
|
|
/**
|
|
* Makes a bottom tool window the active tab.
|
|
*
|
|
* @param id - the tool window id from the panel.
|
|
*/
|
|
function chooseBottom(id: string): void {
|
|
if (id === "find" || id === "terminal" || id === "problems" || id === "references" || id === "changes" || id === "log") {
|
|
bottomTool.value = id;
|
|
}
|
|
}
|
|
|
|
/** Hides the active bottom tool window. */
|
|
function closeBottom(): void {
|
|
bottomStore.value.hide();
|
|
}
|
|
|
|
/** Withdraws the command handlers; filled while mounted. */
|
|
let withdraw: (() => void)[] = [];
|
|
|
|
onMounted(() => {
|
|
find.start();
|
|
terminal.start();
|
|
problems.start();
|
|
changes.start();
|
|
vcsLog.start();
|
|
setCommitOpener((hash) => void commands.execute(SHOW_COMMIT_COMMAND, { hash }));
|
|
withdraw = [
|
|
commands.provide("view.toggleProjectTree", {
|
|
run: () => {
|
|
toggleLeft("project");
|
|
},
|
|
}),
|
|
commands.provide("find.open", {
|
|
run: (params) => {
|
|
bottomTool.value = "find";
|
|
return find.open(params);
|
|
},
|
|
}),
|
|
commands.provide("terminal.open", {
|
|
run: (params) => {
|
|
bottomTool.value = "terminal";
|
|
return terminal.open(params);
|
|
},
|
|
enabled: () => commands.isEnabled("terminal.create"),
|
|
}),
|
|
commands.provide("problems.open", {
|
|
run: () => {
|
|
bottomTool.value = "problems";
|
|
problems.open();
|
|
},
|
|
}),
|
|
commands.provide("vcs.openChanges", {
|
|
run: () => {
|
|
bottomTool.value = "changes";
|
|
changes.open();
|
|
},
|
|
}),
|
|
commands.provide("vcs.commit", {
|
|
run: () => {
|
|
bottomTool.value = "changes";
|
|
changes.focusMessage();
|
|
},
|
|
}),
|
|
commands.provide("vcs.refresh", {
|
|
run: () => changes.refresh(),
|
|
enabled: () => commands.isEnabled("git.status"),
|
|
}),
|
|
commands.provide(SHOW_LOG_COMMAND, {
|
|
run: () => {
|
|
bottomTool.value = "log";
|
|
return vcsLog.open();
|
|
},
|
|
enabled: () => project.root !== null,
|
|
}),
|
|
commands.provide(SHOW_HISTORY_COMMAND, {
|
|
run: (params) => {
|
|
bottomTool.value = "log";
|
|
return vcsLog.runShowHistory(params, editor.activeTab?.path ?? null);
|
|
},
|
|
enabled: () => project.root !== null,
|
|
}),
|
|
commands.provide(SHOW_COMMIT_COMMAND, {
|
|
run: async (params) => {
|
|
const hash = (params as { hash?: unknown } | null)?.hash;
|
|
if (typeof hash !== "string" || !/^[0-9a-f]{4,64}$/i.test(hash)) {
|
|
return;
|
|
}
|
|
bottomTool.value = "log";
|
|
await vcsLog.open();
|
|
await vcsLog.select(hash);
|
|
},
|
|
enabled: () => project.root !== null,
|
|
}),
|
|
commands.provide(TOGGLE_BLAME_COMMAND, {
|
|
run: async (params) => {
|
|
const given = (params as { path?: unknown } | null)?.path;
|
|
if (typeof given !== "string" || given === "") {
|
|
await editor.adopted();
|
|
}
|
|
const path = typeof given === "string" && given !== "" ? given : editor.activeTab?.path;
|
|
if (path !== undefined) {
|
|
toggleBlame(path);
|
|
}
|
|
},
|
|
enabled: () => project.root !== null,
|
|
}),
|
|
commands.provide(SHOW_CHUNK_COMMAND, {
|
|
run: async () => {
|
|
const view = activeView();
|
|
if (view) {
|
|
await openChunkPopup(view, view.state.doc.lineAt(view.state.selection.main.head).number - 1);
|
|
}
|
|
},
|
|
enabled: () => project.root !== null && activeView() !== null,
|
|
}),
|
|
commands.provide("view.toggleStructure", {
|
|
run: () => {
|
|
toggleLeft("structure");
|
|
},
|
|
}),
|
|
];
|
|
});
|
|
|
|
onBeforeUnmount(() => {
|
|
for (const fn of withdraw) {
|
|
fn();
|
|
}
|
|
withdraw = [];
|
|
setCommitOpener(() => undefined);
|
|
find.stop();
|
|
terminal.stop();
|
|
problems.stop();
|
|
changes.stop();
|
|
vcsLog.stop();
|
|
});
|
|
</script>
|
|
|
|
<template>
|
|
<div class="main-layout">
|
|
<header
|
|
class="main-layout__header"
|
|
data-test="main-header"
|
|
>
|
|
<slot name="header">
|
|
<AppMenu />
|
|
</slot>
|
|
</header>
|
|
<div class="main-layout__row">
|
|
<nav
|
|
class="main-layout__stripe"
|
|
role="tablist"
|
|
aria-orientation="vertical"
|
|
:aria-label="t('common.toolWindow.stripe')"
|
|
data-test="left-stripe"
|
|
>
|
|
<button
|
|
v-for="tool in leftTools"
|
|
:key="tool.id"
|
|
type="button"
|
|
role="tab"
|
|
class="main-layout__stripe-button"
|
|
:class="{ 'main-layout__stripe-button--active': leftOpen && leftTool === tool.id }"
|
|
:aria-selected="leftOpen && leftTool === tool.id"
|
|
:title="tool.title"
|
|
:aria-label="tool.title"
|
|
:data-test="`stripe-${tool.id}`"
|
|
@click="toggleLeft(tool.id)"
|
|
>
|
|
<component
|
|
:is="tool.icon"
|
|
:size="18"
|
|
/>
|
|
</button>
|
|
</nav>
|
|
<ToolWindow
|
|
v-if="leftOpen"
|
|
v-model:width="leftWidth"
|
|
v-model:open="leftOpen"
|
|
:title="leftTitle"
|
|
>
|
|
<ProjectToolWindow v-show="leftTool === 'project'" />
|
|
<StructureToolWindow v-show="leftTool === 'structure'" />
|
|
</ToolWindow>
|
|
<main
|
|
class="main-layout__editor"
|
|
data-test="main"
|
|
>
|
|
<slot />
|
|
</main>
|
|
</div>
|
|
<BottomPanel
|
|
v-if="bottomActive !== null"
|
|
v-model:height="bottomHeight"
|
|
v-model:open="bottomOpen"
|
|
:title="bottomTools.find((tool) => tool.id === bottomActive)?.title ?? ''"
|
|
:tabs="bottomTools.length > 1 ? bottomTools : []"
|
|
:active="bottomActive"
|
|
@update:active="chooseBottom"
|
|
@close="closeBottom"
|
|
>
|
|
<FindToolWindow v-show="bottomActive === 'find'" />
|
|
<TerminalToolWindow
|
|
v-if="terminal.visible"
|
|
v-show="bottomActive === 'terminal'"
|
|
/>
|
|
<ProblemsToolWindow v-show="bottomActive === 'problems'" />
|
|
<ReferencesToolWindow v-show="bottomActive === 'references'" />
|
|
<ChangesToolWindow v-show="bottomActive === 'changes'" />
|
|
<LogToolWindow
|
|
v-if="vcsLog.visible"
|
|
v-show="bottomActive === 'log'"
|
|
/>
|
|
</BottomPanel>
|
|
<StatusBar />
|
|
<StashDialog />
|
|
</div>
|
|
</template>
|
|
|
|
<style scoped>
|
|
.main-layout {
|
|
display: flex;
|
|
flex-direction: column;
|
|
height: 100%;
|
|
}
|
|
|
|
.main-layout__header {
|
|
display: flex;
|
|
align-items: center;
|
|
flex: none;
|
|
height: 28px;
|
|
padding: 0 var(--lt-space-s, 4px);
|
|
background: var(--lt-bg);
|
|
border-bottom: 1px solid var(--lt-border);
|
|
}
|
|
|
|
.main-layout__row {
|
|
display: flex;
|
|
flex: 1;
|
|
min-height: 0;
|
|
}
|
|
|
|
.main-layout__stripe {
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
gap: var(--lt-space-xs, 2px);
|
|
flex: none;
|
|
padding: var(--lt-space-s, 4px) var(--lt-space-xs, 2px);
|
|
background: var(--lt-bg);
|
|
border-right: 1px solid var(--lt-border);
|
|
}
|
|
|
|
.main-layout__stripe-button {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
padding: var(--lt-space-xs, 2px);
|
|
color: var(--lt-fg-muted);
|
|
background: transparent;
|
|
border: none;
|
|
border-radius: var(--lt-radius, 4px);
|
|
cursor: pointer;
|
|
}
|
|
|
|
.main-layout__stripe-button:hover {
|
|
color: var(--lt-fg);
|
|
background: color-mix(in srgb, var(--lt-fg) 8%, transparent);
|
|
}
|
|
|
|
.main-layout__stripe-button--active {
|
|
color: var(--lt-accent);
|
|
background: color-mix(in srgb, var(--lt-accent) 18%, transparent);
|
|
}
|
|
|
|
.main-layout__stripe-button:focus-visible {
|
|
outline: 2px solid var(--lt-accent);
|
|
}
|
|
|
|
.main-layout__editor {
|
|
flex: 1;
|
|
min-width: 0;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
background: var(--lt-editor-bg);
|
|
}
|
|
</style>
|