@@ -21,14 +21,20 @@ export const WIKILINK_REGEX = /\[\[(.+?)([|#].*?)?\]\]/;
2121export function typeOfFile (
2222 plugin : Quadro ,
2323 file ?: TAbstractFile | string | null ,
24- ) : "Data File" | "Code File" | "Extraction File" | "Template" | "Backup" | "Not Markdown" {
24+ ) :
25+ | "Data File"
26+ | "Code File"
27+ | "Extraction File"
28+ | "Template"
29+ | "Backup"
30+ | "Not Markdown"
31+ | "No File" {
2532 const { app, settings } = plugin ;
26-
2733 if ( ! file ) file = app . workspace . getActiveFile ( ) ;
2834 if ( typeof file === "string" ) file = app . vault . getFileByPath ( file ) ;
2935
30- if ( ! file || ! ( file instanceof TFile ) || file . extension !== "md" ) return "Not Markdown " ;
31-
36+ if ( ! file ) return "No File " ;
37+ if ( ! ( file instanceof TFile ) || file . extension !== "md" ) return "Not Markdown" ;
3238 if ( file . name === "Template.md" ) return "Template" ;
3339 if ( file . path . includes ( BACKUP_DIRNAME ) ) return "Backup" ;
3440 if ( file . path . startsWith ( settings . coding . folder + "/" ) ) return "Code File" ;
@@ -112,6 +118,20 @@ export function activeFileHasInvalidName(app: App): boolean {
112118 return true ;
113119}
114120
121+ /** needed, since Obsidian block-ids are only valid on the last line of a paragraph */
122+ export function moveToLastLineOfParagraph ( editor : Editor ) : number {
123+ let lnum = editor . getCursor ( ) . line ;
124+ while ( true ) {
125+ // beyond end of file, `editor.getLine` also returns "", thus this check suffices
126+ const nextLineIsBlank = editor . getLine ( lnum + 1 ) . trim ( ) === "" ;
127+ const currentLineIsListItem = editor . getLine ( lnum ) . match ( / ^ \s * ( [ - * + ] | [ 0 - 9 ] + \. ) \s / ) ;
128+ if ( nextLineIsBlank || currentLineIsListItem ) break ;
129+ lnum ++ ;
130+ editor . setCursor ( { line : lnum , ch : 0 } ) ;
131+ }
132+ return lnum ;
133+ }
134+
115135//──────────────────────────────────────────────────────────────────────────────
116136
117137/** Changed types breaks some things, such as the display of dates in
0 commit comments