+
`;
-class NoteDetailCode extends TabAwareWidget {
+class CodeTypeWidget extends TypeWidget {
+ static getType() { return "code"; }
+
doRender() {
this.$widget = $(TPL);
this.$editor = this.$widget.find('.note-detail-code-editor');
@@ -58,22 +60,19 @@ class NoteDetailCode extends TabAwareWidget {
//this.onNoteChange(() => this.tabContext.noteChanged());
}
- refresh() {
- // lazy loading above can take time and tab might have been already switched to another note
- if (this.tabContext.note && this.tabContext.note.type === 'code') {
- // CodeMirror breaks pretty badly on null so even though it shouldn't happen (guarded by consistency check)
- // we provide fallback
- this.codeEditor.setValue(this.tabContext.note.content || "");
+ doRefresh() {
+ // CodeMirror breaks pretty badly on null so even though it shouldn't happen (guarded by consistency check)
+ // we provide fallback
+ this.codeEditor.setValue(this.tabContext.note.content || "");
- const info = CodeMirror.findModeByMIME(this.tabContext.note.mime);
+ const info = CodeMirror.findModeByMIME(this.tabContext.note.mime);
- if (info) {
- this.codeEditor.setOption("mode", info.mime);
- CodeMirror.autoLoadMode(this.codeEditor, info.mode);
- }
-
- this.show();
+ if (info) {
+ this.codeEditor.setOption("mode", info.mime);
+ CodeMirror.autoLoadMode(this.codeEditor, info.mode);
}
+
+ this.show();
}
show() {
@@ -127,4 +126,4 @@ class NoteDetailCode extends TabAwareWidget {
}
}
-export default NoteDetailCode;
\ No newline at end of file
+export default CodeTypeWidget;
\ No newline at end of file
diff --git a/src/public/javascripts/widgets/detail/note_detail_file.js b/src/public/javascripts/widgets/type_widgets/file.js
similarity index 95%
rename from src/public/javascripts/widgets/detail/note_detail_file.js
rename to src/public/javascripts/widgets/type_widgets/file.js
index 52bfebbfe..1069eef53 100644
--- a/src/public/javascripts/widgets/detail/note_detail_file.js
+++ b/src/public/javascripts/widgets/type_widgets/file.js
@@ -2,10 +2,10 @@ import utils from "../../services/utils.js";
import server from "../../services/server.js";
import toastService from "../../services/toast.js";
import noteDetailService from "../../services/note_detail.js";
-import TabAwareWidget from "../tab_aware_widget.js";
+import TypeWidget from "./type_widget.js";
const TPL = `
-