update and fix
This commit is contained in:
1 parent
358ddca2f0
commit
fcbf1492b7
26 files changed
+8596
-8272
No files matched your search
+64
-64
@@ -1,65 +1,65 @@
|
||||
import { App, Editor, MarkdownFileInfo, MarkdownView, Notice } from 'obsidian'
|
||||
import BindThemPlugin from './main'
|
||||
|
||||
/**
|
||||
* FileHelper provides commands for file operations
|
||||
*/
|
||||
export class FileHelper {
|
||||
public app: App
|
||||
private plugin: BindThemPlugin
|
||||
|
||||
constructor(app: App, plugin: BindThemPlugin) {
|
||||
this.app = app
|
||||
this.plugin = plugin
|
||||
}
|
||||
|
||||
/**
|
||||
* Duplicate the current file
|
||||
*/
|
||||
public async duplicateFile(editor: Editor, view: MarkdownView | MarkdownFileInfo): Promise<void> {
|
||||
const activeFile = this.app.workspace.getActiveFile()
|
||||
|
||||
if (activeFile === null) {
|
||||
return
|
||||
}
|
||||
|
||||
const selections = editor.listSelections()
|
||||
const parentPath = activeFile.parent?.path ?? ''
|
||||
const newFilePath =
|
||||
parentPath + '/' + activeFile.basename + ' (copy).' + activeFile.extension
|
||||
|
||||
try {
|
||||
const newFile = await this.app.vault.copy(activeFile, newFilePath)
|
||||
if (view instanceof MarkdownView) {
|
||||
await view.leaf.openFile(newFile)
|
||||
}
|
||||
|
||||
editor.setSelections(selections)
|
||||
} catch (e) {
|
||||
new Notice(String(e))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new file in the same directory as the current file
|
||||
*/
|
||||
public async newAdjacentFile(editor: Editor, view: MarkdownView | MarkdownFileInfo): Promise<void> {
|
||||
const activeFile = this.app.workspace.getActiveFile()
|
||||
|
||||
if (activeFile === null) {
|
||||
return
|
||||
}
|
||||
|
||||
const parentPath = activeFile.parent?.path ?? ''
|
||||
const newFilePath = parentPath + '/' + 'Untitled.md'
|
||||
|
||||
try {
|
||||
const newFile = await this.app.vault.create(newFilePath, '')
|
||||
if (view instanceof MarkdownView) {
|
||||
await view.leaf.openFile(newFile)
|
||||
}
|
||||
} catch (e) {
|
||||
new Notice(String(e))
|
||||
}
|
||||
}
|
||||
import { App, Editor, MarkdownFileInfo, MarkdownView, Notice } from 'obsidian'
|
||||
import BindThemPlugin from './main'
|
||||
|
||||
/**
|
||||
* FileHelper provides commands for file operations
|
||||
*/
|
||||
export class FileHelper {
|
||||
public app: App
|
||||
private plugin: BindThemPlugin
|
||||
|
||||
constructor(app: App, plugin: BindThemPlugin) {
|
||||
this.app = app
|
||||
this.plugin = plugin
|
||||
}
|
||||
|
||||
/**
|
||||
* Duplicate the current file
|
||||
*/
|
||||
public async duplicateFile(editor: Editor, view: MarkdownView | MarkdownFileInfo): Promise<void> {
|
||||
const activeFile = this.app.workspace.getActiveFile()
|
||||
|
||||
if (activeFile === null) {
|
||||
return
|
||||
}
|
||||
|
||||
const selections = editor.listSelections()
|
||||
const parentPath = activeFile.parent?.path ?? ''
|
||||
const newFilePath =
|
||||
parentPath + '/' + activeFile.basename + ' (copy).' + activeFile.extension
|
||||
|
||||
try {
|
||||
const newFile = await this.app.vault.copy(activeFile, newFilePath)
|
||||
if (view instanceof MarkdownView) {
|
||||
await view.leaf.openFile(newFile)
|
||||
}
|
||||
|
||||
editor.setSelections(selections)
|
||||
} catch (e) {
|
||||
new Notice(String(e))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new file in the same directory as the current file
|
||||
*/
|
||||
public async newAdjacentFile(editor: Editor, view: MarkdownView | MarkdownFileInfo): Promise<void> {
|
||||
const activeFile = this.app.workspace.getActiveFile()
|
||||
|
||||
if (activeFile === null) {
|
||||
return
|
||||
}
|
||||
|
||||
const parentPath = activeFile.parent?.path ?? ''
|
||||
const newFilePath = parentPath + '/' + 'Untitled.md'
|
||||
|
||||
try {
|
||||
const newFile = await this.app.vault.create(newFilePath, '')
|
||||
if (view instanceof MarkdownView) {
|
||||
await view.leaf.openFile(newFile)
|
||||
}
|
||||
} catch (e) {
|
||||
new Notice(String(e))
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user