diff --git a/manifest.json b/manifest.json index 3c3b51e..49483ce 100644 --- a/manifest.json +++ b/manifest.json @@ -1 +1 @@ -{"id":"ridian","name":"Ridian","version":"0.1.1","minAppVersion":"0.15.0","description":"Execute R code blocks and display outputs and plots & render documents with Quarto within Obsidian.","author":"Michel Nivard","isDesktopOnly":true} \ No newline at end of file +{"id":"ridian","name":"Ridian","version":"0.1.2","minAppVersion":"0.15.0","description":"Execute R code blocks and display outputs and plots & render documents with Quarto within Obsidian.","author":"Michel Nivard","isDesktopOnly":true} \ No newline at end of file diff --git a/package.json b/package.json index 76ab3e2..ec25e34 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "Ridian", - "version": "0.1.1", + "version": "0.1.2", "description": "Execute R code blocks and display outputs and plots within Obsidian.", "main": "main.js", "scripts": { diff --git a/src/CombinedPlugin.ts b/src/CombinedPlugin.ts index cd5273a..d8a80d4 100644 --- a/src/CombinedPlugin.ts +++ b/src/CombinedPlugin.ts @@ -206,7 +206,7 @@ export default class CombinedPlugin extends Plugin { private handleCompletion(items: any[]) { - console.log('handleCompletion called with items:', items); + if (items.length === 0) { if (this.currentDropdown) { @@ -313,7 +313,7 @@ private handleCursorActivity(editor: Editor) { // Close the Completion Dropdown if it's open if (this.currentDropdown) { - console.log('Inside function call. Closing Completion Dropdown.'); +- this.currentDropdown.close(); this.currentDropdown = null; } @@ -325,7 +325,7 @@ private handleCursorActivity(editor: Editor) { // Close the Signature Help Dropdown if it's open if (this.signatureHelpDropdown) { - console.log('Outside function call. Closing Signature Help Dropdown.'); + - this.signatureHelpDropdown.close(); this.signatureHelpDropdown = null; } @@ -339,7 +339,6 @@ private showSignatureHelp(editor: Editor, cursor: EditorPosition) { const { codeWithAll, startLine } = getCurrentCodeChunk(editor, cursor.line); if (!codeWithAll) { - console.log('No code chunk found. Closing Signature Help Dropdown.'); this.closeSignatureHelpDropdown(); return; } @@ -361,8 +360,6 @@ private showSignatureHelp(editor: Editor, cursor: EditorPosition) { }; // Log the uri and position - console.log('Virtual URI:', virtualUri); - console.log('Cursor position:', position); // Send didOpen notification for the code chunk this.rLanguageServer.sendNotification('textDocument/didOpen', { @@ -393,9 +390,9 @@ private showCompletion(editor: Editor, cursor: EditorPosition) { const { codeWithAll, startLine } = getCurrentCodeChunk(editor, cursor.line); if (!codeWithAll) { - console.log('No code chunk found. Closing Completion Dropdown.'); + if (this.currentDropdown) { - console.log('No code chunk found. Closing existing dropdown.'); + this.currentDropdown.close(); this.currentDropdown = null; } @@ -418,9 +415,7 @@ private showCompletion(editor: Editor, cursor: EditorPosition) { character: cursor.ch, }; - // Log the uri and position - console.log('Virtual URI:', virtualUri); - console.log('Cursor position:', position); + // Send didOpen notification for the code chunk this.rLanguageServer.sendNotification('textDocument/didOpen', { diff --git a/src/RCodeEvaluator.ts b/src/RCodeEvaluator.ts index eded386..62beb81 100644 --- a/src/RCodeEvaluator.ts +++ b/src/RCodeEvaluator.ts @@ -640,11 +640,11 @@ options(device = function(...) jpeg(filename = tempfile(), width=800, height=600 return rProcess; } - function escapeMarkdown(text: string): string { - return text.replace(/([\\`*_{}[\]()#+\-!>|])/g, '\\$1'); + return text.replace(/([\\`*_{}[\]()#+\-!>|])/g, '\u200b$1'); } + function insertOutputWithCallout( editor: Editor, endLine: number, @@ -653,12 +653,12 @@ function insertOutputWithCallout( widgetPaths: string[], uniqueId: string, options: { [key: string]: string }, - isError: boolean = false // Optional parameter to style errors differently + isError: boolean = false ) { const contentLines: string[] = []; - + const contentLines2: string[] = []; + if (output && output.trim() !== '') { - // Escape markdown special characters in the output const escapedOutput = escapeMarkdown(output.trim()); const outputLines = escapedOutput.split('\n').map((line) => '> ' + line); contentLines.push(...outputLines); @@ -667,23 +667,31 @@ function insertOutputWithCallout( imagePaths.forEach((imagePath) => { const vaultImagePath = `${imagePath}`; const imageMarkdown = `![center|480](${vaultImagePath})`; - contentLines.push(`> ${imageMarkdown}`); + contentLines2.push(`> ${imageMarkdown}`); }); widgetPaths.forEach((widgetPath) => { const widgetMarkdown = ``; - contentLines.push(`> ${widgetMarkdown}`); + contentLines2.push(`> ${widgetMarkdown}`); }); - if (contentLines.length === 0) { + if (contentLines.length === 0 && contentLines2.length === 0) { return; } - // Use a different callout type or add a class for errors if needed - let calloutType = isError ? 'ERROR' : 'OUTPUT'; - let outputContent = `> [!${calloutType}]+ {#output-${uniqueId}}\n`; + const calloutType = isError ? 'ERROR' : 'OUTPUT'; + const calloutTitle = `> [!${calloutType}]+ {#output-${uniqueId}}`; + + let outputContent = `${calloutTitle}\n`; + if (contentLines.length !== 0) { + outputContent += '> \`\`\`\n'; outputContent += contentLines.join('\n') + '\n'; + outputContent += '> \`\`\`\n'; + } + if (contentLines2.length !== 0) { + outputContent += contentLines2.join('\n') + '\n'; outputContent += '> \n'; + } let existingOutputStart = -1; let existingOutputEnd = -1; @@ -691,15 +699,16 @@ function insertOutputWithCallout( for (let i = 0; i < totalLines; i++) { const line = editor.getLine(i); - if (line.trim() === `> [!${calloutType}]+ {#output-${uniqueId}}`) { + if (line.trim().startsWith(`> [!${calloutType}]`) && line.includes(`{#output-${uniqueId}}`)) { existingOutputStart = i; existingOutputEnd = i; while (existingOutputEnd + 1 < totalLines) { const nextLine = editor.getLine(existingOutputEnd + 1); - if (!nextLine.startsWith('> ') && nextLine.trim() !== '') { + if (nextLine.trim() === '' || nextLine.startsWith('> ')) { + existingOutputEnd++; + } else { break; } - existingOutputEnd++; } break; } @@ -716,6 +725,7 @@ function insertOutputWithCallout( } + function removeOutputCallout(editor: Editor, uniqueId: string) { let existingOutputStart = -1; let existingOutputEnd = -1; diff --git a/versions.json b/versions.json index ef7827f..3f6761a 100644 --- a/versions.json +++ b/versions.json @@ -1,3 +1,3 @@ { - "0.1.1": "0.15.0" + "0.1.2": "0.15.0" }