From e12b6d41d056b39284972a1b87f35f46f145f7b7 Mon Sep 17 00:00:00 2001 From: abchen Date: Fri, 10 May 2024 00:19:25 +0800 Subject: [PATCH] =?UTF-8?q?feat(model):=20=E4=B9=A6=E7=AD=BE=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/stores/bookmark-store.ts | 21 +++++++-------------- src/stores/bookmark.ts | 20 +++++++++----------- 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/src/stores/bookmark-store.ts b/src/stores/bookmark-store.ts index 01d6780..94edcc5 100644 --- a/src/stores/bookmark-store.ts +++ b/src/stores/bookmark-store.ts @@ -23,7 +23,6 @@ import { import {BookmarkGroup, IBookmarkGroup} from './bookmark-group'; import {DEFAULT_BOOKMARK_GROUP_ID} from '../constants/bookmark'; import {isProxy} from 'util/types'; -import {DEFAULT_BOOKMARK_COLOR} from '../constants'; const BookmarkGroupDataModel = types.model('BookmarkGroupDataModel', { id: types.string, @@ -277,7 +276,6 @@ export const BookmarksStore = types ? bookmark.customColor : { name: bookmark.color || 'default', - sortedIndex: -1, }; const fsPath = workspace.asRelativePath(fileUri.fsPath, false); @@ -287,8 +285,8 @@ export const BookmarksStore = types )?.bookmarks.length || 0; const idxInFileGroup = - self.bookmarksGroupedByFile.find(it => it.fileId === fsPath)?.bookmarks - .length || 0; + self.bookmarksGroupedByFile.find(it => it.fileUri.fsPath === fsPath) + ?.bookmarks.length || 0; const idxInCustomGroup = self.bookmarksGroupedByCustom.find(it => it.id === bookmark.groupId) @@ -296,18 +294,16 @@ export const BookmarksStore = types let idxInWorkspaceGroup = 0; const workspaceGroup = self.bookmarksGroupedByWorkspace.find(it => - it.files.find(f => f.fileId === fsPath), + it.files.find(f => f.fileUri.fsPath === fsPath), ); if (!workspaceGroup) { idxInWorkspaceGroup = 0; } else { idxInWorkspaceGroup = - workspaceGroup.files.find(it => it.fileId === fsPath)?.bookmarks - .length || 0; + workspaceGroup.files.find(it => it.fileUri.fsPath === fsPath) + ?.bookmarks.length || 0; } - rangesOrOptions.hoverMessage = createHoverMessage(bookmark, true, true); - _bookmark = BookmarkProcessorModel.create({ id: id || generateUUID(), label, @@ -354,12 +350,9 @@ export const BookmarksStore = types it => it.name === TreeViewGroupEnum.FILE, ); - if ( - !fileGroupInfo || - !fileGroupInfo.data.find(it => it.id === _bookmark.fileId) - ) { + if (!fileGroupInfo || !fileGroupInfo.data.find(it => it.id === fsPath)) { addFileGroupInfo({ - id: _bookmark.fileId, + id: fsPath, sortedIndex: fileGroupInfo ? fileGroupInfo.data.length : 0, }); } diff --git a/src/stores/bookmark.ts b/src/stores/bookmark.ts index b5eaab1..13b792c 100644 --- a/src/stores/bookmark.ts +++ b/src/stores/bookmark.ts @@ -168,7 +168,7 @@ export const Bookmark = types * @param idx */ function updateColorSortedIndex(idx: number) { - // self.customColor.sortedIndex = idx; + self.sortedInfo.color = idx; } /** @@ -176,7 +176,7 @@ export const Bookmark = types * @param idx */ function updateWorkspaceSortedIndex(idx: number) { - // self.workspaceFolder.sortedIndex = idx; + self.sortedInfo.workspace = idx; } /** @@ -184,7 +184,8 @@ export const Bookmark = types * @param idx */ function updateFileSortedIndex(idx: number) { - // self.fileUri.sortedIndex = idx; + self.sortedInfo.file = idx; + self.sortedInfo.default = idx; } /** @@ -199,13 +200,7 @@ export const Bookmark = types } } - function afterCreate() { - // self.rangesOrOptions.hoverMessage = createHoverMessage( - // self as IBookmark, - // true, - // true, - // ); - } + function afterCreate() {} return { afterCreate, @@ -234,7 +229,7 @@ export const BookmarkProcessorModel: ISnapshotProcessor< SnapshotIn, SnapshotOut > = types.snapshotProcessor(Bookmark, { - preProcessor(snapshot: SnapshotIn) { + preProcessor(snapshot: SnapshotIn) { console.log(snapshot); return { ...snapshot, @@ -244,6 +239,9 @@ export const BookmarkProcessorModel: ISnapshotProcessor< }, } as unknown as SnapshotOut; }, + postProcessor(snapshot: SnapshotOut, node) { + return snapshot; + }, }); export type IBookmarkProcessorModel = Instance;