Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 33 additions & 12 deletions frontend/src/views/host/file-management/code-editor/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@
</template>

<script lang="ts" setup>
import { createFile, getFileContent, getFilesTree, saveFileContent } from '@/api/modules/files';
import { batchCheckFiles, createFile, getFileContent, getFilesTree, saveFileContent } from '@/api/modules/files';
import i18n from '@/lang';
import { MsgError, MsgSuccess, MsgWarning } from '@/utils/message';
import * as monaco from 'monaco-editor';
Expand Down Expand Up @@ -556,6 +556,11 @@ const removeTab = (targetPath: TabPaneName) => {
}
selectTab.value = activeName;
fileTabs.value = tabs.filter((tab) => tab.path !== targetPath);
saveTabsToStorage();
if (fileTabs.value.length === 0) {
selectTab.value = '';
editor.dispose();
}
};

if (isEdit.value) {
Expand All @@ -567,8 +572,10 @@ const removeTab = (targetPath: TabPaneName) => {
})
.then(() => {
updateTabs();
saveContent();
getContent(selectTab.value, '');
if (fileTabs.value.length > 0) {
saveContent();
getContent(selectTab.value, '');
}
})
.catch(() => {
updateTabs();
Expand All @@ -579,7 +586,9 @@ const removeTab = (targetPath: TabPaneName) => {
});
} else {
updateTabs();
getContent(selectTab.value, '');
if (fileTabs.value.length > 0) {
getContent(selectTab.value, '');
}
}
};

Expand All @@ -601,6 +610,7 @@ const removeAllTab = (targetPath: string, type: 'left' | 'right' | 'all') => {
const newTabs = type === 'all' ? [] : filterTabs();
fileTabs.value = newTabs;
selectTab.value = activeName;
saveTabsToStorage();

if (type === 'all') {
selectTab.value = '';
Expand Down Expand Up @@ -635,8 +645,6 @@ const removeAllTab = (targetPath: string, type: 'left' | 'right' | 'all') => {
.catch(onCancel);
} else {
updateTabs();
if (type === 'all') editor.dispose();
else getContent(activeName, '');
}
};

Expand All @@ -648,6 +656,7 @@ const removeOtherTab = (targetPath: string) => {
const updateTabs = () => {
fileTabs.value = [targetTab];
selectTab.value = targetTab.path;
saveTabsToStorage();
getContent(targetTab.path, '');
};

Expand Down Expand Up @@ -902,17 +911,30 @@ const saveContent = async () => {
}
};

const acceptParams = (props: EditProps) => {
const acceptParams = async (props: EditProps) => {
form.value.content = props.content;
oldFileContent.value = props.content;
form.value.path = props.path;
currentPath.value = getDirectoryPath(props.path);
directoryPath.value = getDirectoryPath(props.path);
fileExtension.value = props.extension;
fileName.value = props.name;
const savedTabs = loadTabsFromStorage();

let savedTabs = loadTabsFromStorage();
const withoutCurrent = savedTabs.filter((tab) => tab.path !== props.path);
const merged = [...withoutCurrent, { path: props.path, name: props.name }];
if (withoutCurrent.length > 0) {
try {
const existRes = await batchCheckFiles(withoutCurrent.map((t) => t.path));
const existList = existRes?.data ?? [];
const existingPaths = new Set(existList.map((r) => r.path));
savedTabs = withoutCurrent.filter((t) => existingPaths.has(t.path));
} catch {
savedTabs = withoutCurrent;
}
} else {
savedTabs = [];
}
const merged = [...savedTabs, { path: props.path, name: props.name }];
fileTabs.value = merged.slice(-maxTabs);
selectTab.value = props.path;

Expand Down Expand Up @@ -1024,9 +1046,8 @@ const getContent = (path: string, extension: string) => {
}
const exists = fileTabs.value.some((tab) => tab.path === path);
if (exists) {
fileTabs.value = fileTabs.value
.filter((t) => t.path !== path)
.concat([{ name: res.data.name, path: res.data.path }]);
const tab = fileTabs.value.find((t) => t.path === path);
if (tab) tab.name = res.data.name;
} else {
fileTabs.value.push({
name: res.data.name,
Expand Down
92 changes: 48 additions & 44 deletions frontend/src/views/host/file-management/code-editor/tabs/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,60 @@
<el-tabs
v-model="currentTab"
type="card"
:closable="props.fileTabs.length > 1"
:closable="true"
class="monaco-editor monaco-editor-background"
@tab-remove="props.onRemoveTab"
@tab-change="props.onChangeTab"
>
<el-tab-pane v-for="item in props.fileTabs" :key="item.path" :name="item.path">
<template #label>
<el-tooltip v-if="props.fileTabs.length == 1" :content="item.path" placement="bottom-start">
<span>{{ item.name }}</span>
</el-tooltip>
<template v-if="props.fileTabs.length > 1">
<el-dropdown
size="small"
:id="item.path"
:ref="(el) => setDropdownRef(item.path, el)"
trigger="contextmenu"
placement="bottom"
@visible-change="(visible) => onDropdownVisibleChange(visible, item.path)"
>
<span class="el-dropdown-link">
<el-tooltip :content="item.path" placement="bottom-start">
{{ item.name }}
</el-tooltip>
</span>
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item @click="props.onRemoveTab(item.path)">
<el-icon><Close /></el-icon>
{{ $t('commons.button.close') }}
</el-dropdown-item>
<el-dropdown-item @click="props.onRemoveAllTab(item.path, 'left')">
<el-icon><DArrowLeft /></el-icon>
{{ $t('tabs.closeLeft') }}
</el-dropdown-item>
<el-dropdown-item @click="props.onRemoveAllTab(item.path, 'right')">
<el-icon><DArrowRight /></el-icon>
{{ $t('tabs.closeRight') }}
</el-dropdown-item>
<el-dropdown-item @click="props.onRemoveOtherTab(item.path)">
<el-icon><More /></el-icon>
{{ $t('tabs.closeOther') }}
</el-dropdown-item>
<el-dropdown-item @click="props.onRemoveAllTab(item.path, 'all')">
<el-icon><Operation /></el-icon>
{{ $t('tabs.closeAll') }}
</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
</template>
<el-dropdown
size="small"
:id="item.path"
:ref="(el) => setDropdownRef(item.path, el)"
trigger="contextmenu"
placement="bottom"
@visible-change="(visible) => onDropdownVisibleChange(visible, item.path)"
>
<span class="el-dropdown-link">
<el-tooltip :content="item.path" placement="bottom-start">
{{ item.name }}
</el-tooltip>
</span>
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item @click="props.onRemoveTab(item.path)">
<el-icon><Close /></el-icon>
{{ $t('commons.button.close') }}
</el-dropdown-item>
<el-dropdown-item
:disabled="props.fileTabs.length <= 1"
@click="props.onRemoveAllTab(item.path, 'left')"
>
<el-icon><DArrowLeft /></el-icon>
{{ $t('tabs.closeLeft') }}
</el-dropdown-item>
<el-dropdown-item
:disabled="props.fileTabs.length <= 1"
@click="props.onRemoveAllTab(item.path, 'right')"
>
<el-icon><DArrowRight /></el-icon>
{{ $t('tabs.closeRight') }}
</el-dropdown-item>
<el-dropdown-item
:disabled="props.fileTabs.length <= 1"
@click="props.onRemoveOtherTab(item.path)"
>
<el-icon><More /></el-icon>
{{ $t('tabs.closeOther') }}
</el-dropdown-item>
<el-dropdown-item @click="props.onRemoveAllTab(item.path, 'all')">
<el-icon><Operation /></el-icon>
{{ $t('tabs.closeAll') }}
</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
</template>
</el-tab-pane>
</el-tabs>
Expand Down
Loading