feat: editor keyboard shortcuts (quit/save)
This commit is contained in:
parent
52c94d22ad
commit
157b68ccef
@ -280,7 +280,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.note-textarea {
|
.note-textarea {
|
||||||
@apply h-full max-h-full w-full resize-none rounded-2xl bg-transparent p-3.5 font-mono outline-none focus:border-4 focus:border-[var(--light-accent)]/60;
|
@apply h-full max-h-full min-h-1/2 w-full resize-none rounded-2xl bg-transparent p-3.5 font-mono outline-none focus:border-4 focus:border-[var(--light-accent)]/60;
|
||||||
}
|
}
|
||||||
|
|
||||||
.note-save-button {
|
.note-save-button {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { onMount } from "svelte"
|
import { onMount } from "svelte"
|
||||||
import { marked, Renderer } from "marked"
|
import { marked } from "marked"
|
||||||
import { TITLE_MAX_LENGTH } from "$lib/const"
|
import { TITLE_MAX_LENGTH } from "$lib/const"
|
||||||
import type { FullNote } from "$lib/client"
|
import type { FullNote } from "$lib/client"
|
||||||
|
|
||||||
@ -46,6 +46,23 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const exitEditMode = () => {
|
||||||
|
isEditing = false
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleKeyDown = (event: KeyboardEvent) => {
|
||||||
|
// Ctrl+Enter or Command+Enter keyboard shortcut for saving the current note
|
||||||
|
if ((event.ctrlKey || event.metaKey) && event.key === "Enter") {
|
||||||
|
event.preventDefault()
|
||||||
|
handleSave()
|
||||||
|
}
|
||||||
|
// Esc keyboard shortcut for quitting edit mode
|
||||||
|
else if (event.key === "Escape") {
|
||||||
|
event.preventDefault()
|
||||||
|
exitEditMode()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const handleSave = () => {
|
const handleSave = () => {
|
||||||
saveNote(editableTitle, editableContent)
|
saveNote(editableTitle, editableContent)
|
||||||
}
|
}
|
||||||
@ -105,8 +122,6 @@
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- TODO: capture Ctrl+Enter keyboard shortcut to save the note contents -->
|
|
||||||
|
|
||||||
<div class="flex h-full flex-col">
|
<div class="flex h-full flex-col">
|
||||||
<!-- Note title -->
|
<!-- Note title -->
|
||||||
<div class="mb-4">
|
<div class="mb-4">
|
||||||
@ -115,6 +130,7 @@
|
|||||||
type="text"
|
type="text"
|
||||||
bind:value={editableTitle}
|
bind:value={editableTitle}
|
||||||
on:input={handleTitleChange}
|
on:input={handleTitleChange}
|
||||||
|
on:keydown={handleKeyDown}
|
||||||
placeholder="Title"
|
placeholder="Title"
|
||||||
class="note-title-input"
|
class="note-title-input"
|
||||||
/>
|
/>
|
||||||
@ -132,7 +148,7 @@
|
|||||||
<h1 class="border-[var(--light-text)]/20 border-b pb-2 text-2xl font-bold">
|
<h1 class="border-[var(--light-text)]/20 border-b pb-2 text-2xl font-bold">
|
||||||
{note.title || "Untitled Note"}
|
{note.title || "Untitled Note"}
|
||||||
</h1>
|
</h1>
|
||||||
<div class="note-char-count ml-1">
|
<div class="note-char-count">
|
||||||
Last updated: {new Date(note.noteUpdatedAt).toLocaleString()}
|
Last updated: {new Date(note.noteUpdatedAt).toLocaleString()}
|
||||||
{#if !isEditing}
|
{#if !isEditing}
|
||||||
<!-- Minus 1 due to versioning beginning at 2 in the DB -->
|
<!-- Minus 1 due to versioning beginning at 2 in the DB -->
|
||||||
@ -150,6 +166,7 @@
|
|||||||
bind:this={textarea}
|
bind:this={textarea}
|
||||||
bind:value={editableContent}
|
bind:value={editableContent}
|
||||||
on:input={handleContentChange}
|
on:input={handleContentChange}
|
||||||
|
on:keydown={handleKeyDown}
|
||||||
placeholder="Markdown contents"
|
placeholder="Markdown contents"
|
||||||
class="note-textarea"
|
class="note-textarea"
|
||||||
></textarea>
|
></textarea>
|
||||||
|
@ -191,7 +191,7 @@
|
|||||||
<!-- Note content area -->
|
<!-- Note content area -->
|
||||||
<main class="main-content">
|
<main class="main-content">
|
||||||
{#if $currentFullNote}
|
{#if $currentFullNote}
|
||||||
<NoteEditor note={$currentFullNote} {isEditing} {saveNote} />
|
<NoteEditor note={$currentFullNote} bind:isEditing {saveNote} />
|
||||||
{:else}
|
{:else}
|
||||||
<div class="flex h-full flex-col items-center justify-center">
|
<div class="flex h-full flex-col items-center justify-center">
|
||||||
<p class="mb-4 text-lg">None selected</p>
|
<p class="mb-4 text-lg">None selected</p>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user