From 26232618d46bd9dcd438202f7060505d07856086 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Tue, 19 Feb 2019 11:46:40 -0700 Subject: [PATCH] Make Ctrl-S save note in editor --- www/js/editnote.js | 18 +++++++++++++++--- www/pages/editor.html | 12 ++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/www/js/editnote.js b/www/js/editnote.js index 2364912..1a7712f 100644 --- a/www/js/editnote.js +++ b/www/js/editnote.js @@ -12,9 +12,9 @@ function saveme(callback) { return; } app.toast.create({ - text: '   Saving...', - closeTimeout: 2 * 60 * 1000 // two whole minutes should be enough for *any* connection. - }).open(); + text: '   Saving...', + closeTimeout: 2 * 60 * 1000 // two whole minutes should be enough for *any* connection. + }).open(); save_in_progress = true; sync(); // update textareas with correct content @@ -75,6 +75,18 @@ function exiteditor() { } } +$(window).bind('keydown', function (event) { + if (event.ctrlKey || event.metaKey) { + switch (String.fromCharCode(event.which).toLowerCase()) { + case 's': + event.preventDefault(); + sync(); + saveme(); + break; + } + } +}); + $("#noteframe").on("load", function () { init(); }); \ No newline at end of file diff --git a/www/pages/editor.html b/www/pages/editor.html index 3e61a3e..469e27c 100644 --- a/www/pages/editor.html +++ b/www/pages/editor.html @@ -63,6 +63,18 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/. "horizontal-rule" ] }); + + window.addEventListener('keydown', function (event) { + if (event.ctrlKey || event.metaKey) { + switch (String.fromCharCode(event.which).toLowerCase()) { + case 's': + event.preventDefault(); + window.parent.sync(); + window.parent.saveme(); + break; + } + } + }); } function getMarkdown() {