From 66ff9bd186c34d32076d401dfc73d19a0428eb01 Mon Sep 17 00:00:00 2001 From: evazion Date: Wed, 29 Jul 2020 04:24:18 -0500 Subject: [PATCH] notes: don't mark note as unsaved when previewing. Bug: previewing a note would mark the note as unsaved even if the note hadn't been changed. Fix: mark the note as unsaved when the user types something into the note edit box, not when the note is previewed. --- app/javascript/src/javascripts/notes.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/javascript/src/javascripts/notes.js b/app/javascript/src/javascripts/notes.js index 3cb38efb7..229e3a9d9 100644 --- a/app/javascript/src/javascripts/notes.js +++ b/app/javascript/src/javascripts/notes.js @@ -569,16 +569,13 @@ class Note { } let $textarea = $(''); + $textarea.val(note.original_body); $textarea.css({ width: "97%", height: "85%", resize: "none", }); - if (!note.is_new()) { - $textarea.val(note.original_body); - } - let $dialog = $('
'); let note_title = note.is_new() ? 'Creating new note' : `Editing note #${note.id}`; @@ -598,6 +595,7 @@ class Note { }, open: () => { Utility.keydown("ctrl+return", "save_note", () => this.save($dialog, note), ".note-edit-dialog textarea"); + $(".note-edit-dialog textarea").on("input.danbooru", (e) => this.on_input(note)); $(".note-box").addClass("editing"); }, close: () => { @@ -615,6 +613,10 @@ class Note { $textarea.selectEnd(); } + static on_input(note) { + note.box.$note_box.addClass("unsaved"); + } + static async save($dialog, note) { let $note_box = note.box.$note_box; let text = $dialog.find("textarea").val(); @@ -648,8 +650,6 @@ class Note { static async preview($dialog, note) { let text = $dialog.find("textarea").val(); - - note.box.$note_box.addClass("unsaved"); note.body.preview_text(text); }