Repository navigation
Wiki比較パネルの初期表示不一致を修正 #827
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
NishikawaKoharu
wants to merge
1
commit into
RCOSDP:develop
Choose a base branch
from
NishikawaKoharu:feature/fix-wiki-compare-default-current
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Wiki比較パネルの初期表示不一致を修正 #827
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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'; | ||
|
|
@@ -131,13 +143,7 @@ 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"); | ||
|
|
@@ -148,7 +154,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, | ||
|
|
@@ -334,7 +343,7 @@ var defaultOptions = { | |
| menuVisible: true, | ||
| canEdit: true, | ||
| viewVersion: 'current', | ||
| compareVersion: 'previous', | ||
| compareVersion: 'current', | ||
| urls: { | ||
| content: '', | ||
| draft: '', | ||
|
|
@@ -343,6 +352,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'); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. previous を指定しても、対応する選択肢を取得できなかった場合は、黙って current に切り替わる点が気になりました。過去版が存在しない場合の扱いと、DOMを取得できない等の想定外の状態を区別し、後者はwarning等で確認できるとよいかもしれません。ご検討ください。 |
||
| 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? | ||
|
|
@@ -372,7 +402,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; | ||
|
|
@@ -545,13 +575,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()); | ||
| } | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
この関数は、エディタが予期しない状態であったときも、実際に空の内容であった場合も、同様に空文字列を返すため、何かトラブルが起きたときに調査しづらいコードに見えます。
if (mEdit && typeof mEdit.action === 'function') {が成立しない場合に、エラーとまではしなくても、consoleにwarning等は出力できると良いかもしれません。ご検討ください。