Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 23 additions & 19 deletions addons/wiki/static/wikiPageMilkdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ const wikiId = (wikiCtx.wiki.wikiName === 'home') ? wikiCtx.node.id : window.con
const wsPrefix = (window.location.protocol === 'https:') ? 'wss://' : 'ws://';
const wsUrl = wsPrefix + window.contextVars.wiki.urls.y_websocket;

function getEditorMarkdown() {
var content = '';
if (mEdit && typeof mEdit.action === 'function') {
mEdit.action((ctx) => {
const view = ctx.get(mCore.editorViewCtx);
const serializer = ctx.get(mCore.serializerCtx);
content = serializer(view.state.doc);
});
}
return content;
}

import { underlineSchema, underlineInputRule, remarkUnderlineToMarkdown, remarkUnderlineFromMarkdown, toggleUnderlineCommand } from './underline.js';
import { colortextSchema, colortextInputRule, remarkColortextToMarkdown, remarkColortextFromMarkdown, toggleColortextCommand } from './colortext.js';
import { extendedImageSchemaPlugin, extendedInsertImageCommand, extendedUpdateImageCommand, updatedInsertImageInputRule } from './image.js';
Expand Down Expand Up @@ -239,15 +251,11 @@ function ViewWidget(visible, version, viewText, rendered, contentURL, allowMathj
var requestURL;
if (typeof self.version() !== 'undefined') {
if (self.version() === 'preview') {
var toMarkdown = '';
if (mEdit !== undefined) {
mEdit.action((ctx) => {
const view = ctx.get(mCore.editorViewCtx);
const serializer = ctx.get(mCore.serializerCtx);
toMarkdown = serializer(view.state.doc);
});
var toMarkdown = getEditorMarkdown();
// Avoid wiping a preserved draft when the editor was destroyed for version view.
if (toMarkdown) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

一点、確認させてください。変更後が空の場合に、toMarkdownがfalsyとなり、変更前の本文が比較表示に残る可能性を考えました。この検証をされているか、教えてください。

self.displaySource(toMarkdown);
}
self.displaySource(toMarkdown);
if (document.getElementById("editWysiwyg").style.display === "none"){
document.getElementById("mMenuBar").style.display = "";
document.getElementById("mEditorFooter").style.display = "";
Expand All @@ -256,11 +264,9 @@ function ViewWidget(visible, version, viewText, rendered, contentURL, allowMathj
document.getElementById("wikiViewRender").style.display = "none";
} else {
document.getElementById("mMenuBar").style.display = "none";
// Hide the live editor while viewing another version. Do not destroy
// its DOM/instance; recreating collab state can leave an empty editor.
document.getElementById("mEditor").style.display = "none";
const milkdownDivs = document.getElementById("mEditor").querySelectorAll('div.milkdown');
if (milkdownDivs.length > 0) {
milkdownDivs[0].remove();
}
document.getElementById("mEditorFooter").style.display = "none";
document.getElementById("wikiViewRender").style.display = "";
if (self.version() === 'current') {
Expand Down Expand Up @@ -545,13 +551,11 @@ function ViewModel(options){
if (panel === 'compare') {
if(display && self.compareVis()){
self.viewVersion('preview');
var toMarkdown = '';
mEdit.action((ctx) => {
const view = ctx.get(mCore.editorViewCtx);
const serializer = ctx.get(mCore.serializerCtx);
toMarkdown = serializer(view.state.doc);
});
self.viewVM.displaySource(toMarkdown);
var toMarkdown = getEditorMarkdown();
// Avoid clearing Compare's "after" side when the editor markdown is empty.
if (toMarkdown) {
self.viewVM.displaySource(toMarkdown);
}
}
}

Expand Down
Loading