MCPcopy
hub / github.com/marktext/marktext / unlinkFile

Function unlinkFile

packages/desktop/src/renderer/src/store/treeCtrl.ts:217–235  ·  view source on GitHub ↗
(tree: TreeFolder, file: { pathname: string })

Source from the content-addressed store, hash-verified

215 * Remove the given file from the tree list.
216 */
217export const unlinkFile = (tree: TreeFolder, file: { pathname: string }): void => {
218 const { pathname } = file
219 const dirname = window.path.dirname(pathname)
220 const subDirectories = getSubdirectoriesFromRoot(tree.pathname, dirname)
221
222 let currentFolder: TreeFolder = tree
223 let currentSubFolders: TreeFolder[] = tree.folders
224 for (const directoryName of subDirectories) {
225 const childFolder = currentSubFolders.find((f) => f.name === directoryName)
226 if (!childFolder) return
227 currentFolder = childFolder
228 currentSubFolders = childFolder.folders
229 }
230
231 const index = currentFolder.files.findIndex((f) => f.pathname === pathname)
232 if (index !== -1) {
233 currentFolder.files.splice(index, 1)
234 }
235}
236
237/**
238 * Remove the given directory from the tree list.

Callers 1

_processTreeEventFunction · 0.90

Calls 4

dirnameMethod · 0.80
findIndexMethod · 0.80
findMethod · 0.45

Tested by

no test coverage detected