174 lines
5.1 KiB
Vue
174 lines
5.1 KiB
Vue
<script setup lang="ts">
|
|
/**
|
|
* The editor area: one or two editor groups side by side or stacked
|
|
* (`EditorPane.vue`, C10 A1), the close question and the last editor
|
|
* error. Without open tabs it shows the default slot.
|
|
*
|
|
* Save, save all and close run through the global keymap and the
|
|
* palette (`commands/store.ts`): the area supplies their behaviour with the
|
|
* active buffer as context and says when they can run. It also supplies the
|
|
* UI commands `editor.reveal` (`reveal.ts`) and the assist commands
|
|
* (`assist/commands.ts`) and the tab management commands
|
|
* (`tabs/commands.ts`). Diff tabs (M4.3, `vcs/diff/`) share the first
|
|
* group's tab bar; while one is active the diff view replaces that group's
|
|
* editor, and the area supplies the diff commands. Files changed on disk
|
|
* (C10 A2): each pane shows its active tab's banner (`DiskBanner.vue`);
|
|
* the area shows the overwrite question (`OverwritePrompt.vue`), both from
|
|
* `stores/diskConflicts.ts`.
|
|
*/
|
|
import { onBeforeUnmount, onMounted } from "vue";
|
|
import { useCommandsStore } from "../../commands/store";
|
|
import { t } from "../../i18n";
|
|
import { useEditorStore } from "../../stores/editor";
|
|
import { COMPARE_WITH_DISK_COMMAND, useDiskConflictsStore } from "../../stores/diskConflicts";
|
|
import ClosePrompt from "./ClosePrompt.vue";
|
|
import EditorPane from "./EditorPane.vue";
|
|
import { provideTabCommands } from "./tabs/commands";
|
|
import OverwritePrompt from "./OverwritePrompt.vue";
|
|
import { reveal, REVEAL_COMMAND } from "./reveal";
|
|
import * as assist from "./assist/commands";
|
|
import { provideDiffCommands } from "../vcs/diff/commands";
|
|
import { useDiffStore } from "../vcs/diff/diff";
|
|
|
|
const editor = useEditorStore();
|
|
const commands = useCommandsStore();
|
|
const diff = useDiffStore();
|
|
const disk = useDiskConflictsStore();
|
|
|
|
/** Withdraws the command handlers; filled while mounted. */
|
|
let withdraw: (() => void)[] = [];
|
|
|
|
onMounted(() => {
|
|
editor.start();
|
|
disk.start();
|
|
const hasActive = (): boolean => editor.activeTab !== null;
|
|
withdraw = [
|
|
commands.provide("file.save", { run: async () => { await editor.save(); }, enabled: hasActive }),
|
|
commands.provide("file.saveAll", { run: () => editor.saveAll(), enabled: () => editor.tabs.length > 0 }),
|
|
commands.provide("buffer.close", { run: () => editor.requestClose(), enabled: hasActive }),
|
|
commands.provide(REVEAL_COMMAND, { run: (params) => reveal(editor, params) }),
|
|
commands.provide(COMPARE_WITH_DISK_COMMAND, { run: (params) => disk.compareCommand(params), enabled: hasActive }),
|
|
commands.provide(assist.COMPLETE_COMMAND, { run: assist.completeAtCursor, enabled: assist.assistEnabled }),
|
|
commands.provide(assist.QUICK_DOC_COMMAND, { run: assist.quickDocumentation, enabled: assist.assistEnabled }),
|
|
commands.provide(assist.PARAMETER_INFO_COMMAND, { run: assist.parameterInfo, enabled: assist.assistEnabled }),
|
|
...provideDiffCommands(commands),
|
|
...provideTabCommands(commands, editor),
|
|
];
|
|
});
|
|
|
|
onBeforeUnmount(() => {
|
|
for (const fn of withdraw) {
|
|
fn();
|
|
}
|
|
withdraw = [];
|
|
disk.stop();
|
|
editor.stop();
|
|
});
|
|
</script>
|
|
|
|
<template>
|
|
<div
|
|
class="editor-area"
|
|
data-test="editor-area"
|
|
>
|
|
<div
|
|
v-if="editor.tabs.length > 0 || diff.tabs.length > 0"
|
|
class="editor-area__groups"
|
|
:class="{ 'editor-area__groups--down': editor.orientation === 'down' }"
|
|
data-test="editor-groups"
|
|
>
|
|
<EditorPane
|
|
v-for="group in editor.groups"
|
|
:key="group.index"
|
|
:group="group.index"
|
|
/>
|
|
</div>
|
|
<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"
|
|
>
|
|
{{ t("common.dismiss") }}
|
|
</button>
|
|
</div>
|
|
<ClosePrompt />
|
|
<OverwritePrompt />
|
|
</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__groups {
|
|
display: flex;
|
|
flex: 1;
|
|
min-width: 0;
|
|
min-height: 0;
|
|
}
|
|
|
|
.editor-area__groups > * + * {
|
|
border-left: 1px solid var(--lt-border);
|
|
}
|
|
|
|
.editor-area__groups--down {
|
|
flex-direction: column;
|
|
}
|
|
|
|
.editor-area__groups--down > * + * {
|
|
border-left: none;
|
|
border-top: 1px solid var(--lt-border);
|
|
}
|
|
|
|
.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);
|
|
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>
|