Implement chain roles and templates management in Mindnet plugin
- Added support for loading and reloading chain roles and templates from specified YAML configuration files, enhancing the plugin's flexibility. - Introduced new settings for defining paths to chain roles and templates, improving user configurability. - Implemented commands for debugging loaded chain roles and templates, providing users with insights into their configurations. - Enhanced the Mindnet settings interface to include options for managing chain roles and templates paths, improving user experience with clear descriptions and validation features.
This commit is contained in:
1 parent
15385b0129
commit
b0efa32c66
21 files changed
+3226
No files matched your search
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* Section context resolver: determines current section from editor cursor position.
|
||||
*/
|
||||
|
||||
import type { Editor } from "obsidian";
|
||||
import { splitIntoSections } from "../mapping/sectionParser";
|
||||
|
||||
export interface SectionRef {
|
||||
file: string;
|
||||
heading: string | null;
|
||||
}
|
||||
|
||||
export type ZoneKind = "content" | "note_links" | "candidates" | "root";
|
||||
|
||||
export interface SectionContext {
|
||||
file: string;
|
||||
heading: string | null;
|
||||
zoneKind: ZoneKind;
|
||||
sectionIndex: number;
|
||||
}
|
||||
|
||||
const NOTE_LINKS_HEADING = "Note-Verbindungen";
|
||||
const CANDIDATES_HEADING = "Kandidaten";
|
||||
|
||||
/**
|
||||
* Determine section context from editor cursor position.
|
||||
*/
|
||||
export function resolveSectionContext(
|
||||
editor: Editor,
|
||||
filePath: string
|
||||
): SectionContext {
|
||||
const content = editor.getValue();
|
||||
const cursor = editor.getCursor();
|
||||
const cursorLine = cursor.line;
|
||||
|
||||
const sections = splitIntoSections(content);
|
||||
|
||||
// Find section containing cursor line
|
||||
let currentSectionIndex = -1;
|
||||
for (let i = 0; i < sections.length; i++) {
|
||||
const section = sections[i];
|
||||
if (!section) continue;
|
||||
if (
|
||||
section.startLine <= cursorLine &&
|
||||
cursorLine < section.endLine
|
||||
) {
|
||||
currentSectionIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// If no section found, use root (content before first heading)
|
||||
if (currentSectionIndex === -1) {
|
||||
return {
|
||||
file: filePath,
|
||||
heading: null,
|
||||
zoneKind: "root",
|
||||
sectionIndex: 0,
|
||||
};
|
||||
}
|
||||
|
||||
const currentSection = sections[currentSectionIndex];
|
||||
if (!currentSection) {
|
||||
return {
|
||||
file: filePath,
|
||||
heading: null,
|
||||
zoneKind: "root",
|
||||
sectionIndex: 0,
|
||||
};
|
||||
}
|
||||
|
||||
// Determine zone kind based on heading
|
||||
let zoneKind: ZoneKind = "content";
|
||||
const heading = currentSection.heading;
|
||||
if (heading === NOTE_LINKS_HEADING) {
|
||||
zoneKind = "note_links";
|
||||
} else if (heading === CANDIDATES_HEADING) {
|
||||
zoneKind = "candidates";
|
||||
} else if (heading === null) {
|
||||
zoneKind = "root";
|
||||
}
|
||||
|
||||
return {
|
||||
file: filePath,
|
||||
heading: heading,
|
||||
zoneKind,
|
||||
sectionIndex: currentSectionIndex,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user