Fixed bugs

This commit is contained in:
Andrea Alberti 2024-08-13 19:13:03 +02:00
parent 5a4c9248b0
commit 820207a1bc
3 changed files with 20 additions and 14 deletions

View file

@ -14,8 +14,8 @@ import {
// App,
} from 'obsidian';
import { around } from 'monkey-around';
import { AnnotationType, isPluginAnnotation, isPluginsAnnotationsSettings, parse_annotation, PluginAnnotationDict, PluginsAnnotationsSettings } from './types';
import { PluginAnnotationDict_1_4_0, PluginsAnnotationsSettings_1_4_0, PluginsAnnotationsSettings_1_3_0, isPluginAnnotationDictFormat_1_3_0, isSettingsFormat_1_3_0, isSettingsFormat_1_4_0, parse_annotation_1_4_0, } from 'types_legacy'
import { AnnotationType, isPluginAnnotation, isPluginsAnnotationsSettings, parseAnnotation, PluginAnnotationDict, PluginsAnnotationsSettings } from './types';
import { PluginAnnotationDict_1_4_0, PluginsAnnotationsSettings_1_4_0, PluginsAnnotationsSettings_1_3_0, isPluginAnnotationDictFormat_1_3_0, isSettingsFormat_1_3_0, isSettingsFormat_1_4_0, parseAnnotation_1_4_0, } from 'types_legacy'
import { DEFAULT_SETTINGS_1_3_0, DEFAULT_SETTINGS_1_4_0 } from './defaults_legacy';
import { DEFAULT_SETTINGS } from 'defaults';
import { PluginsAnnotationsSettingTab } from 'settings_tab'
@ -78,7 +78,7 @@ export default class PluginsAnnotations extends Plugin {
const upgradedAnnotations: PluginAnnotationDict = {};
for (const pluginId in data.annotations) {
const annotation = data.annotations[pluginId];
const {type,content} = parse_annotation_1_4_0(annotation.anno);
const {type,content} = parseAnnotation_1_4_0(annotation.anno);
upgradedAnnotations[pluginId] = {
name: annotation.name,
desc: content,
@ -329,6 +329,7 @@ export default class PluginsAnnotations extends Plugin {
}
async renderAnnotation(annotation_div: HTMLDivElement, annoType:AnnotationType, desc:string) {
annotation_div.innerText = '';
switch(annoType) {
case AnnotationType.text: {
const p = document.createElement('p');
@ -443,7 +444,6 @@ export default class PluginsAnnotations extends Plugin {
preamble = 'markdown:';
}
console.log("ANNOTATION TEXT:",annotationDesc);
annotation_div.innerText = preamble + '\n' + annotationDesc;
}
}
@ -453,10 +453,13 @@ export default class PluginsAnnotations extends Plugin {
annotation_div.addEventListener('blur', (event:FocusEvent) => {
if(!this.settings.editable) { return; }
annotationDesc = annotation_div.innerText.trim();
const innerText = annotation_div.innerText.trim();
if (isPlaceholder || annotationDesc === '') { // placeholder
console.log(innerText);
if (isPlaceholder || innerText === '') { // placeholder
annotation_div.innerHTML = placeholder;
delete this.settings.annotations[pluginId];
annotation_div.classList.add('plugin-comment-placeholder');
if (this.settings.hide_placeholders) {
annotation_container.classList.add('plugin-comment-placeholder');
@ -465,10 +468,13 @@ export default class PluginsAnnotations extends Plugin {
} else {
isPlaceholder = false;
const {type,content} = parse_annotation(annotationDesc);
const {annoType: type,annoDesc: content} = parseAnnotation(innerText);
annotationDesc = content;
annoType = type;
this.settings.annotations[pluginId] = {
desc: content,
desc: annotationDesc,
name: pluginName,
type: type,
};

View file

@ -50,20 +50,20 @@ export function isPluginAnnotation(anno:unknown): anno is PluginAnnotation {
}
// Function to render the annotation based on preamble
export function parse_annotation(text: string): {type:AnnotationType,content:string} {
export function parseAnnotation(text: string): {annoType:AnnotationType,annoDesc:string} {
const lines = text.split('\n');
const preamble = lines[0].toLowerCase();
const sliced = lines.slice(1).join('\n');
// annotation_div.innerHTML = '';
if (preamble.startsWith('html:')) {
return {type: AnnotationType.html, content: sliced};
return {annoType: AnnotationType.html, annoDesc: sliced};
} else if (preamble.startsWith('markdown:')) {
return {type: AnnotationType.markdown, content: sliced};
return {annoType: AnnotationType.markdown, annoDesc: sliced};
} else if (preamble.startsWith('text:')) {
return {type: AnnotationType.text, content: sliced};
return {annoType: AnnotationType.text, annoDesc: sliced};
} else {
return {type: AnnotationType.markdown, content: text};
return {annoType: AnnotationType.markdown, annoDesc: text};
}
}

View file

@ -28,7 +28,7 @@ export function isSettingsFormat_1_4_0(s:unknown): s is PluginsAnnotationsSettin
}
// Function to render the annotation based on preamble
export function parse_annotation_1_4_0(text: string): {type:AnnotationType,content:string} {
export function parseAnnotation_1_4_0(text: string): {type:AnnotationType,content:string} {
const lines = text.split('\n');
const preamble = lines[0].toLowerCase();
const sliced = lines.slice(1).join('\n');