Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 14, 2025

Overview

This PR addresses the feature request to improve the EmbeddableMarkdownEditor implementation and create a MetadataEditor infrastructure based on patterns from obsidian-better-properties.

Problem Statement

The original issues were:

  1. Task 1: Code in MarkdownEditor.ts was not properly implemented even though it was functional
  2. Task 2: Unable to access the MetadataEditor within the EmbeddableMarkdownEditor

Changes Made

1. EmbeddableMarkdownEditor Enhancements

The markdown editor has been significantly improved following best practices from obsidian-better-properties:

New Features

  • File Path Support: Added filePath parameter to enable proper link rendering ([[wikilinks]])
  • Enhanced Callbacks:
    • onFocus - Triggered when editor gains focus
    • onEditorClick - Custom click event handler
    • onEscape - Escape key handler (previously commented out)
  • Focus Control: Added focus option to control initial focus state
  • Filtered Extensions: Added filteredExtensions array to exclude specific CodeMirror extensions
  • Better onChange API: Now passes editor instance as second parameter for easier access

Implementation Improvements

  • Uses Constructor<MarkdownScrollableEditView> type from obsidian-typings
  • Proper file path handling for link rendering
  • Enhanced activeEditor management with MarkdownView containment detection
  • Improved method overriding via monkey-patching
  • Better code organization and documentation

Usage Example

const editor = createEmbeddableMarkdownEditor(
    plugin.app,
    container,
    {
        value: "Initial content",
        placeholder: "Start typing...",
        focus: true,
        onFocus: (editor) => console.log("Editor focused"),
        onChange: (update, editor) => {
            console.log("Current content:", editor.value);
        },
        onEscape: (editor) => editor.destroy(),
    },
    "path/to/file.md"  // Enables proper link rendering
);

2. MetadataEditor Infrastructure

Created a complete MetadataEditor patching infrastructure that can be optionally integrated:

New Module: src/services/MetadataEditor/

Core Functions:

  • resolveMetadataEditorPrototype(plugin) - Extracts MetadataEditor prototype from app
    • Optimized to use existing MarkdownView when available
    • Falls back to temporary view creation only if needed
  • patchMetadataEditor(plugin) - Applies patches using monkey-around
    • Patches load() and synchronize() methods
    • Uses unique dedupe keys per method to prevent conflicts
    • Auto-registers cleanup with plugin lifecycle

Design Principles:

  • Optional/Modular: Can be enabled when specific use cases require it
  • Type-Safe: Uses MetadataEditor types from obsidian-typings package
  • Safe Patching: Uses monkey-around with dedupe pattern
  • Extensible: Provides foundation for future enhancements

Integration Example

// Basic integration (in main.ts onLayoutReady callback)
try {
    patchMetadataEditor(this);
    console.log("MetadataEditor patch applied");
} catch (error) {
    console.error("Failed to apply patch:", error);
}

See src/services/MetadataEditor/INTEGRATION_EXAMPLE.ts for complete integration patterns including settings toggle.

3. Bug Fixes

Fixed unrelated TypeScript error in MultiSuggest.ts where tag sorting needed proper type handling.

Documentation

Comprehensive documentation has been added:

  • 📄 ENHANCEMENT_SUMMARY.md - Complete technical overview and migration guide
  • 📄 src/services/MetadataEditor/README.md - MetadataEditor API documentation
  • 📄 src/services/MetadataEditor/INTEGRATION_EXAMPLE.ts - Three integration patterns with examples

Testing

  • ✅ All TypeScript compilation passes without errors
  • ✅ Production build successful (main.js: 866KB)
  • ✅ No breaking changes - 100% backward compatible
  • ✅ All code review feedback addressed

Backward Compatibility

All changes are fully backward compatible:

  • The filePath parameter is optional (defaults to empty string)
  • The onChange callback signature is extended (old usage still works)
  • All new properties have sensible defaults
  • Existing code continues to work without modifications

Files Changed

Modified:

  • src/services/MarkdownEditor.ts - Enhanced implementation
  • src/components/AddOrEditTaskRC.tsx - Updated to use new API
  • src/services/MultiSuggest.ts - Fixed type error

Added:

  • src/services/MetadataEditor/ - Complete module with 4 files
  • ENHANCEMENT_SUMMARY.md - Comprehensive documentation

References

Next Steps

The MetadataEditor infrastructure is ready for use when needed. To enable it, follow the integration examples in INTEGRATION_EXAMPLE.ts. The enhanced EmbeddableMarkdownEditor is already active and improves the task editing experience with better link rendering and focus management.

Original prompt

This section details on the original issue you should resolve

<issue_title>FR : Enhance the EmbeddableMarkdownEditor and create a MetadataEditor</issue_title>
<issue_description>## Problem Statement

  • Task 1 : A lot of code inside the MarkdownEditor.ts has not been implemented properly even though its working without any bug.
  • Task 2 : Not able to get the MetadataEditor inside my EmbeddableMarkdownEditor.

Possible Solution

Comments on the Issue (you are @copilot in this section)

Fixes #432


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Enhance the EmbeddableMarkdownEditor and create MetadataEditor FR: Enhance EmbeddableMarkdownEditor and create MetadataEditor infrastructure Oct 14, 2025
Copilot AI requested a review from tu2-atmanand October 14, 2025 14:47
@tu2-atmanand tu2-atmanand added feature New feature or enhancement request future idea New Future or improvement, but not urgent, can be implemented in new branch optimization The algo/code can be optimized. A better approach labels Oct 17, 2025
@github-project-automation github-project-automation bot moved this to Future Ideas in Task Board Dev Oct 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or enhancement request future idea New Future or improvement, but not urgent, can be implemented in new branch optimization The algo/code can be optimized. A better approach

Projects

Status: Future Ideas

Development

Successfully merging this pull request may close these issues.

2 participants