feat: 实现编辑器标签页切换时恢复滚动条位置
This commit is contained in:
@@ -31,6 +31,8 @@ export interface FileTab {
|
||||
saveStatus: SaveStatus;
|
||||
saveError: string | null;
|
||||
isModified: boolean;
|
||||
scrollTop?: number; // 编辑器垂直滚动位置
|
||||
scrollLeft?: number; // 编辑器水平滚动位置
|
||||
}
|
||||
|
||||
// --- 辅助函数 (移到外部并导出) ---
|
||||
@@ -183,6 +185,8 @@ export const useFileEditorStore = defineStore('fileEditor', () => {
|
||||
saveStatus: 'idle',
|
||||
saveError: null,
|
||||
isModified: false,
|
||||
scrollTop: 0, // 初始化滚动位置
|
||||
scrollLeft: 0, // 初始化滚动位置
|
||||
};
|
||||
tabs.value.set(tabId, newTab);
|
||||
// setActiveTab(tabId); // 移除同步激活
|
||||
@@ -552,6 +556,15 @@ export const useFileEditorStore = defineStore('fileEditor', () => {
|
||||
// }
|
||||
};
|
||||
|
||||
// +++ 更新标签页滚动位置 +++
|
||||
const updateTabScrollPosition = (tabId: string, scrollTop: number, scrollLeft: number) => {
|
||||
const tab = tabs.value.get(tabId);
|
||||
if (tab) {
|
||||
tab.scrollTop = scrollTop;
|
||||
tab.scrollLeft = scrollLeft;
|
||||
}
|
||||
};
|
||||
|
||||
// 移除旧的 updateContent,因为它只更新活动标签页
|
||||
// const updateContent = (newContent: string) => { ... };
|
||||
|
||||
@@ -618,5 +631,6 @@ export const useFileEditorStore = defineStore('fileEditor', () => {
|
||||
changeEncoding, // +++ 暴露更改编码的方法 +++
|
||||
triggerPopup, // 暴露新的触发方法
|
||||
// setEditorVisibility, // 移除
|
||||
updateTabScrollPosition, // +++ 暴露更新滚动位置的方法 +++
|
||||
};
|
||||
});
|
||||
|
||||
@@ -95,6 +95,8 @@ export const useSessionStore = defineStore('session', () => {
|
||||
editorActions.closeTabsToTheRightInSession(sessionId, targetTabId);
|
||||
const closeTabsToTheLeftInSession = (sessionId: string, targetTabId: string) =>
|
||||
editorActions.closeTabsToTheLeftInSession(sessionId, targetTabId);
|
||||
const updateTabScrollPositionInSession = (sessionId: string, tabId: string, scrollTop: number, scrollLeft: number) =>
|
||||
editorActions.updateTabScrollPositionInSession(sessionId, tabId, scrollTop, scrollLeft);
|
||||
|
||||
// Command Input Actions
|
||||
const updateSessionCommandInput = (sessionId: string, content: string) =>
|
||||
@@ -136,6 +138,7 @@ export const useSessionStore = defineStore('session', () => {
|
||||
closeOtherTabsInSession,
|
||||
closeTabsToTheRightInSession,
|
||||
closeTabsToTheLeftInSession,
|
||||
updateTabScrollPositionInSession, // +++ 导出新的 action +++
|
||||
openRdpModal,
|
||||
closeRdpModal,
|
||||
openVncModal,
|
||||
|
||||
@@ -297,6 +297,26 @@ export const closeTabsToTheRightInSession = (sessionId: string, targetTabId: str
|
||||
idsToClose.forEach(id => closeEditorTabInSession(sessionId, id));
|
||||
};
|
||||
|
||||
export const updateTabScrollPositionInSession = (
|
||||
sessionId: string,
|
||||
tabId: string,
|
||||
scrollTop: number,
|
||||
scrollLeft: number
|
||||
) => {
|
||||
const session = sessions.value.get(sessionId);
|
||||
if (!session) {
|
||||
console.error(`[EditorActions] 尝试在不存在的会话 ${sessionId} 中更新标签页 ${tabId} 的滚动位置`);
|
||||
return;
|
||||
}
|
||||
const tab = session.editorTabs.value.find(t => t.id === tabId);
|
||||
if (tab) {
|
||||
tab.scrollTop = scrollTop;
|
||||
tab.scrollLeft = scrollLeft;
|
||||
} else {
|
||||
console.warn(`[EditorActions] 尝试更新会话 ${sessionId} 中不存在的标签页 ${tabId} 的滚动位置`);
|
||||
}
|
||||
};
|
||||
|
||||
export const closeTabsToTheLeftInSession = (sessionId: string, targetTabId: string) => {
|
||||
const session = sessions.value.get(sessionId);
|
||||
if (!session) return;
|
||||
|
||||
Reference in New Issue
Block a user