Merge pull request #27 from Timmmm/patch-1

Add ctrl-S save shortcut
pull/144/head
Henrique Dias 2016-09-17 08:21:29 +01:00 committed by GitHub
commit 0185a9e143
1 changed files with 18 additions and 4 deletions

View File

@ -802,10 +802,8 @@ document.addEventListener("editor", (event) => {
Array.from(addFrontMatterItemButtons).forEach(button => {
button.addEventListener('click', addFrontMatterItem);
});
document.querySelector('form').addEventListener('submit', (event) => {
event.preventDefault();
let saveContent = function() {
let data = form2js(document.querySelector('form'));
let html = button.changeToLoading();
let request = new XMLHttpRequest();
@ -818,7 +816,23 @@ document.addEventListener("editor", (event) => {
button.changeToDone((request.status != 200), html);
}
}
}
document.querySelector('form').addEventListener('submit', (event) => {
event.preventDefault();
saveContent();
});
window.addEventListener('keydown', (event) => {
if (event.ctrlKey || event.metaKey) {
switch (String.fromCharCode(event.which).toLowerCase()) {
case 's':
event.preventDefault();
saveContent();
break;
}
}
}
return false;
});