Add keyboard shortcuts

This commit is contained in:
2026-04-10 10:03:00 +02:00
parent 06a3da1d54
commit 57e2ce23fe
3 changed files with 38 additions and 13 deletions

View File

@@ -41,10 +41,23 @@
hr: function () { wrap('\n\n---\n\n', '', ''); },
};
var keyMap = {};
document.querySelectorAll('[data-action]').forEach(function (btn) {
btn.addEventListener('click', function () {
var action = actions[btn.dataset.action];
if (action) action();
});
if (btn.dataset.key) {
keyMap[btn.dataset.key] = actions[btn.dataset.action];
}
});
document.addEventListener('keydown', function (e) {
if (!e.altKey || !e.shiftKey) return;
var action = keyMap[e.key];
if (action) {
e.preventDefault();
action();
}
});
})();

View File

@@ -0,0 +1,11 @@
(function () {
document.addEventListener('keydown', function (e) {
if (!e.altKey || !e.shiftKey) return;
switch (e.key) {
case 'E':
e.preventDefault();
window.location.href = window.location.pathname + '?edit';
break;
}
});
})();

View File

@@ -5,6 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>{{.Title}}</title>
<link rel="stylesheet" href="/_/style.css" />
<script src="/_/global-shortcuts.js"></script>
</head>
<body>
<header>
@@ -13,27 +14,27 @@
{{range .Crumbs}}<span class="sep">/</span
><a href="{{.URL}}">{{.Name}}</a>{{end}}
</nav>
{{if .CanEdit}}<a class="edit-btn" href="?edit">EDIT</a>{{end}}
{{if .CanEdit}}<a class="edit-btn" href="?edit" title="Edit (E)">EDIT</a>{{end}}
</header>
<main>
{{if .EditMode}}
<form class="edit-form" method="POST" action="{{.PostURL}}">
<div class="editor-toolbar">
<button type="button" class="btn-tool" data-action="bold" title="Bold">**</button>
<button type="button" class="btn-tool" data-action="italic" title="Italic">*</button>
<button type="button" class="btn-tool" data-action="bold" data-key="B" title="Bold (B)">**</button>
<button type="button" class="btn-tool" data-action="italic" data-key="I" title="Italic (I)">*</button>
<span class="toolbar-sep"></span>
<button type="button" class="btn-tool" data-action="h1" title="Heading 1">#</button>
<button type="button" class="btn-tool" data-action="h2" title="Heading 2">##</button>
<button type="button" class="btn-tool" data-action="h3" title="Heading 3">###</button>
<button type="button" class="btn-tool" data-action="h1" data-key="1" title="Heading 1 (1)">#</button>
<button type="button" class="btn-tool" data-action="h2" data-key="2" title="Heading 2 (2)">##</button>
<button type="button" class="btn-tool" data-action="h3" data-key="3" title="Heading 3 (3)">###</button>
<span class="toolbar-sep"></span>
<button type="button" class="btn-tool" data-action="code" title="Inline code">`</button>
<button type="button" class="btn-tool" data-action="codeblock" title="Code block">```</button>
<button type="button" class="btn-tool" data-action="code" data-key="C" title="Inline code (C)">`</button>
<button type="button" class="btn-tool" data-action="codeblock" data-key="K" title="Code block (K)">```</button>
<span class="toolbar-sep"></span>
<button type="button" class="btn-tool" data-action="link" title="Link">[]</button>
<button type="button" class="btn-tool" data-action="quote" title="Blockquote">&gt;</button>
<button type="button" class="btn-tool" data-action="ul" title="Unordered list">-</button>
<button type="button" class="btn-tool" data-action="ol" title="Ordered list">1.</button>
<button type="button" class="btn-tool" data-action="hr" title="Horizontal rule">---</button>
<button type="button" class="btn-tool" data-action="link" data-key="L" title="Link (L)">[]</button>
<button type="button" class="btn-tool" data-action="quote" data-key="Q" title="Blockquote (Q)">&gt;</button>
<button type="button" class="btn-tool" data-action="ul" data-key="U" title="Unordered list (U)">-</button>
<button type="button" class="btn-tool" data-action="ol" data-key="O" title="Ordered list (O)">1.</button>
<button type="button" class="btn-tool" data-action="hr" data-key="R" title="Horizontal rule (R)">---</button>
</div>
<textarea name="content" id="editor" autofocus>{{.RawContent}}</textarea>
<div class="form-actions">