Skip to content

feat: add dedicated Markdown Viewer Editor Window#39

Open
Dheolarh wants to merge 1 commit into
gwaredd:mainfrom
Dheolarh:feature/markdown-editor-window
Open

feat: add dedicated Markdown Viewer Editor Window#39
Dheolarh wants to merge 1 commit into
gwaredd:mainfrom
Dheolarh:feature/markdown-editor-window

Conversation

@Dheolarh

Copy link
Copy Markdown

Summary

This PR adds a dedicated MarkdownWindow (Editor Window) that allows developers to view and read markdown files independently of their Inspector selections.

Why this is needed

Previously, markdown files could only be previewed directly inside the Inspector window. However, when developers are setting up scenes, editing components, or interacting with Hierarchy objects, the Inspector is overridden by the selected GameObjects, preventing them from reading markdown setup/guide files simultaneously.

Key Features

  1. Access: Added to the menu via Window -> Markdown Viewer Window.
  2. Double-Click Hook ([OnOpenAsset]): Double-clicking a .md or .markdown file in the Project window automatically opens it in this window instead of launching an external text editor.
  3. Sync Selection & Retention:
    • Includes a Sync Selection toggle in the toolbar.
    • When checked: selecting a markdown asset in the project will automatically show it in the window. Selecting any non-markdown asset (e.g. GameObjects, Materials, folders) will keep the last viewed markdown file active.
    • When unchecked: locks the view onto the current markdown document.
  4. Drag & Drop support: Shows a clean drag-and-drop zone box when no file is loaded, allowing files to be dragged directly into the window.
  5. Play Mode / Domain Reload Support: Handles Unity assembly reloads gracefully. The viewer instance is safely restored when entering or exiting Play Mode.
  6. Auto-Reload: Automatically detects updates or re-imports to the loaded file and repaints the layout.
Screenshot 2026-06-22 173629

Copilot AI review requested due to automatic review settings June 22, 2026 16:42

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a dedicated Unity EditorWindow (MarkdownWindow) for viewing markdown files independently of the Inspector, including menu access and editor hooks to open markdown assets directly in the window.

Changes:

  • Introduces MarkdownWindow EditorWindow with toolbar controls, selection sync, and drag-and-drop loading.
  • Adds [OnOpenAsset] handling so double-clicking .md / .markdown opens in the viewer window.
  • Adds auto-reload behavior to refresh the displayed markdown when the underlying asset changes.

Reviewed changes

Copilot reviewed 1 out of 2 changed files in this pull request and generated 6 comments.

File Description
Editor/Scripts/MarkdownWindow.cs New EditorWindow implementation for standalone markdown viewing, selection sync, drag/drop loading, and auto-reload.
Editor/Scripts/MarkdownWindow.cs.meta Adds the Unity .meta file for the new script asset.
Files not reviewed (1)
  • Editor/Scripts/MarkdownWindow.cs.meta: Generated file

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1 to +2
fileFormatVersion: 2
guid: ecd1fe6ba17648143a9f5dc9db49ae2a No newline at end of file
Comment on lines +10 to +14
private TextAsset mMarkdownFile;
private string mLoadedContent;
private MarkdownViewer mViewer;
private Vector2 mScrollPosition;
private bool mSyncSelection = true;
Comment on lines +78 to +82
// Auto-reload if file contents changed on disk
if (mMarkdownFile != null && mMarkdownFile.text != mLoadedContent)
{
ReloadCurrentFile();
}
Comment on lines +119 to +122
var path = AssetDatabase.GetAssetPath(mMarkdownFile);
mLoadedContent = mMarkdownFile.text;
var skin = Preferences.DarkSkin ? mSkinDark : mSkinLight;
mViewer = new MarkdownViewer(skin, path, mLoadedContent, () => position.width);
Comment on lines +124 to +128
else
{
mViewer = null;
mLoadedContent = null;
}
Comment on lines +235 to +254
DragAndDrop.visualMode = DragAndDropVisualMode.Copy;

if (evt.type == EventType.DragPerform)
{
DragAndDrop.AcceptDrag();
foreach (var draggedObject in DragAndDrop.objectReferences)
{
if (draggedObject is TextAsset textAsset)
{
var path = AssetDatabase.GetAssetPath(textAsset);
var ext = Path.GetExtension(path).ToLower();
if (ext == ".md" || ext == ".markdown")
{
LoadMarkdownFile(textAsset);
Repaint();
break;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants