Save default editor mode in local storage
authorAdam Dullage <redacted>
Fri, 17 Mar 2023 08:15:38 +0000 (08:15 +0000)
committerAdam Dullage <redacted>
Fri, 17 Mar 2023 08:15:38 +0000 (08:15 +0000)
flatnotes/src/components/NoteViewerEditor.vue

index b9884eccbbcb03ffbfc4250c82010de5c2121bbd..2272d74355cbb17a44c53bec73ae33fdb0823e08 100644 (file)
@@ -86,7 +86,7 @@
       <div v-else class="note flex-grow-1">
         <editor
           :initialValue="initialContent"
-          initialEditType="markdown"
+          :initialEditType="loadDefaultEditorMode()"
           previewStyle="tab"
           ref="toastUiEditor"
           :options="editorOptions"
@@ -304,6 +304,23 @@ export default {
       }
     },
 
+    saveDefaultEditorMode: function () {
+      let isWysiwygMode = this.$refs.toastUiEditor.invoke("isWysiwygMode");
+      localStorage.setItem(
+        "defaultEditorMode",
+        isWysiwygMode ? "wysiwyg" : "markdown"
+      );
+    },
+
+    loadDefaultEditorMode: function () {
+      let defaultWysiwygMode = localStorage.getItem("defaultEditorMode");
+      if (defaultWysiwygMode) {
+        return defaultWysiwygMode;
+      } else {
+        return "markdown";
+      }
+    },
+
     clearDraftSaveTimeout: function () {
       if (this.draftSaveTimeout != null) {
         clearTimeout(this.draftSaveTimeout);
@@ -338,6 +355,8 @@ export default {
       let parent = this;
       let newContent = this.getEditorContent();
 
+      this.saveDefaultEditorMode();
+
       // Title Validation
       if (typeof this.titleInput == "string") {
         this.titleInput = this.titleInput.trim();
@@ -353,7 +372,7 @@ export default {
       const reservedCharacters = /[<>:"/\\|?*]/;
       if (reservedCharacters.test(this.titleInput)) {
         this.$bvToast.toast(
-          "Due to filename restrictions, the following characters are not allowed in a note title: <>:\"/\\|?*",
+          'Due to filename restrictions, the following characters are not allowed in a note title: <>:"/\\|?*',
           {
             variant: "danger",
             noCloseButton: true,
git clone https://git.99rst.org/PROJECT