Skip to content
Open
Show file tree
Hide file tree
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
46 changes: 30 additions & 16 deletions addons/wiki/static/wikiPageMilkdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,13 +396,8 @@ async function createMEditor(editor, vm, template) {
uploader,
enableHtmlFileUploader,
}));
const debouncedMarkdownUpdated = $osf.debounce(async (ctx, markdown, prevMarkdown) => {
const compareWidgetElement = document.getElementById('compareWidget');

if (compareWidgetElement && compareWidgetElement.style.display !== 'none') {
vm.viewVM.displaySource(markdown);
}

const debouncedUndoButtonUpdate = $osf.debounce(async (ctx) => {
const view = ctx.get(mCore.editorViewCtx);
const state = view.state;
const undoElement = document.getElementById('undoWiki');
Expand All @@ -413,7 +408,10 @@ async function createMEditor(editor, vm, template) {
}
}, 300);
ctx.get(mListener.listenerCtx).markdownUpdated((ctx, markdown, prevMarkdown) => {
debouncedMarkdownUpdated(ctx, markdown, prevMarkdown);
// Keep the live editor body in displaySource even while Compare is
// closed, so opening Compare after edits diffs against the edits.
vm.viewVM.displaySource(markdown);
debouncedUndoButtonUpdate(ctx);
});
ctx.update(mCore.editorViewOptionsCtx, (prev) => ({
...prev,
Expand Down Expand Up @@ -658,7 +656,7 @@ var defaultOptions = {
menuVisible: true,
canEdit: true,
viewVersion: 'current',
compareVersion: 'previous',
compareVersion: 'current',
urls: {
content: '',
draft: '',
Expand All @@ -667,6 +665,27 @@ var defaultOptions = {
metadata: {}
};

// Normalize compare target to a dropdown option value.
// Default / empty -> current (edit vs latest saved). Explicit previous -> prior version number.
function resolveCompareVersion(compareVersion) {
if (!compareVersion) {
return 'current';
}
if (compareVersion !== 'previous') {
return String(compareVersion);
}
var select = document.getElementById('compareVersionSelect');

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

revious を指定しても、対応する選択肢を取得できなかった場合は、黙って current に切り替わる点が気になりました。というのと、 RCOSDP/RDM-osf.io#827 と同じ指摘をしているのですが、二重管理になっていませんでしょうか。両リポジトリの役割と、修正を同期する方針を確認させてください。

if (select) {
for (var i = 0; i < select.options.length; i++) {
var val = select.options[i].value;
if (val && val !== 'current') {
return val;
}
}
}
return 'current';
}

function ViewModel(options){
var self = this;
// enabled?
Expand Down Expand Up @@ -696,7 +715,7 @@ function ViewModel(options){
self.status = ko.observable('connecting');
self.throttledStatus = ko.observable(self.status());

self.compareVersion = ko.observable(options.compareVersion);
self.compareVersion = ko.observable(resolveCompareVersion(options.compareVersion));
self.viewVersion = ko.observable(options.viewVersion);
self.draftURL = options.urls.draft;
self.contentURL = options.urls.content;
Expand Down Expand Up @@ -881,13 +900,8 @@ 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);
// Always use the live editor body as the "after" side of the diff.
self.viewVM.displaySource(getEditorMarkdown());
}
}

Expand Down
3 changes: 2 additions & 1 deletion website/static/js/pages/wiki-edit-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ var comparable = (ctx.panelsUsed.indexOf('compare') !== -1);
var menuVisible = (ctx.panelsUsed.indexOf('menu') !== -1);

var viewVersion = ctx.versionSettings.view || (editable ? 'preview' : 'current');
var compareVersion = ctx.versionSettings.compare || 'previous';
// Default Current = editing body vs latest saved. Explicit previous is remapped server-side.
var compareVersion = ctx.versionSettings.compare || 'current';

var wikiPageOptions = {
editVisible: editable,
Expand Down
Loading