🐛 tab support
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { readdir, readFile, writeFile, mkdir, unlink, rename as fsRename, rm } from 'fs/promises'
|
||||
import { join, dirname } from 'path'
|
||||
import { join, dirname, basename } from 'path'
|
||||
import type { FileNode, RevisionMeta } from '../renderer/types/editor'
|
||||
|
||||
const DRAFT_ROOT =
|
||||
@@ -249,3 +249,14 @@ export async function createSubdirectory(parentPath: string, name: string): Prom
|
||||
await mkdir(newDir, { recursive: true })
|
||||
return newDir
|
||||
}
|
||||
|
||||
export async function moveFileOrDir(sourcePath: string, targetDirPath: string): Promise<string> {
|
||||
assertInDraftRoot(sourcePath)
|
||||
const destDir = targetDirPath === '__root__' ? DRAFT_ROOT : targetDirPath
|
||||
assertInDraftRoot(destDir)
|
||||
const newPath = join(destDir, basename(sourcePath))
|
||||
assertInDraftRoot(newPath)
|
||||
if (newPath === sourcePath) return sourcePath
|
||||
await fsRename(sourcePath, newPath)
|
||||
return newPath
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { ipcMain, dialog, BrowserWindow } from 'electron'
|
||||
import { readFileSync } from 'fs'
|
||||
import { extname, basename } from 'path'
|
||||
import { listDraftFiles, readMarkdownFile, writeMarkdownFile, getProjectWordCount, saveOrderFile, readSession, writeSession, saveRevision, listRevisions, loadRevision, deleteRevision, renameFileOrDir, deleteFileOrDir, createMarkdownFile, createSubdirectory } from './fileSystem'
|
||||
import { listDraftFiles, readMarkdownFile, writeMarkdownFile, getProjectWordCount, saveOrderFile, readSession, writeSession, saveRevision, listRevisions, loadRevision, deleteRevision, renameFileOrDir, deleteFileOrDir, createMarkdownFile, createSubdirectory, moveFileOrDir } from './fileSystem'
|
||||
import { streamMessage } from './aiService'
|
||||
import type { AIPayload, Attachment } from '../renderer/types/editor'
|
||||
|
||||
@@ -66,6 +66,10 @@ export function registerIpcHandlers(): void {
|
||||
return await createSubdirectory(parentPath, name)
|
||||
})
|
||||
|
||||
ipcMain.handle('fs:move', async (_event, sourcePath: string, targetDirPath: string) => {
|
||||
return await moveFileOrDir(sourcePath, targetDirPath)
|
||||
})
|
||||
|
||||
ipcMain.handle('fs:pickAttachments', async (event): Promise<Attachment[]> => {
|
||||
const win = BrowserWindow.fromWebContents(event.sender)
|
||||
const result = await dialog.showOpenDialog(win!, {
|
||||
|
||||
Reference in New Issue
Block a user