fix: heading-regex tag corruption, live command toggles, adjacent-file collision, stale selection listeners
- HEADING_REGEX now requires a space/EOL after '#' so tag lines (#project ...) are no longer misdetected as headings and corrupted. - Command enable/disable settings now take effect immediately via checkCallback/editorCheckCallback instead of requiring a reload. - New Adjacent File auto-increments (Untitled.md, Untitled 1.md, ...) instead of throwing once Untitled.md already exists. - Selection-change tracking is delegated from document instead of a one-time .cm-content scan, so editors opened after startup are covered. See CHANGELOG.md for details.
This commit is contained in:
1 parent
fcbf1492b7
commit
254fcc1b41
5 files changed
+128
-34
No files matched your search
+17
-2
@@ -41,7 +41,9 @@ export class FileHelper {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new file in the same directory as the current file
|
||||
* Create a new file in the same directory as the current file.
|
||||
* If "Untitled.md" already exists, finds the next available
|
||||
* "Untitled N.md" name (mirrors Obsidian's own new-note behavior).
|
||||
*/
|
||||
public async newAdjacentFile(editor: Editor, view: MarkdownView | MarkdownFileInfo): Promise<void> {
|
||||
const activeFile = this.app.workspace.getActiveFile()
|
||||
@@ -51,7 +53,7 @@ export class FileHelper {
|
||||
}
|
||||
|
||||
const parentPath = activeFile.parent?.path ?? ''
|
||||
const newFilePath = parentPath + '/' + 'Untitled.md'
|
||||
const newFilePath = this.getAvailablePath(parentPath, 'Untitled', 'md')
|
||||
|
||||
try {
|
||||
const newFile = await this.app.vault.create(newFilePath, '')
|
||||
@@ -62,4 +64,17 @@ export class FileHelper {
|
||||
new Notice(String(e))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the first unused "<basename>.md" / "<basename> N.md" path in a folder
|
||||
*/
|
||||
private getAvailablePath(parentPath: string, basename: string, extension: string): string {
|
||||
let candidate = `${parentPath}/${basename}.${extension}`
|
||||
let n = 1
|
||||
while (this.app.vault.getAbstractFileByPath(candidate) !== null) {
|
||||
candidate = `${parentPath}/${basename} ${n}.${extension}`
|
||||
n++
|
||||
}
|
||||
return candidate
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user