1
Fork 0

Add the shortcut input to the snippet editor.

This commit is contained in:
Bauke 2023-12-11 15:42:07 +01:00
parent 3604cfe674
commit 0170231862
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
3 changed files with 30 additions and 4 deletions

View File

@ -226,6 +226,7 @@ type SnippetEditorState = {
markdown: MarkdownSnippet["markdown"]; markdown: MarkdownSnippet["markdown"];
name: MarkdownSnippet["name"]; name: MarkdownSnippet["name"];
position: MarkdownSnippet["position"]; position: MarkdownSnippet["position"];
shortcut: MarkdownSnippet["shortcut"];
toBeRemoved: boolean; toBeRemoved: boolean;
}; };
@ -233,7 +234,8 @@ class SnippetEditor extends Component<SnippetEditorProps, SnippetEditorState> {
constructor(props: SnippetEditorProps) { constructor(props: SnippetEditorProps) {
super(props); super(props);
const {enabled, inDropdown, markdown, name, position} = props.snippet.value; const {enabled, inDropdown, markdown, name, position, shortcut} =
props.snippet.value;
this.state = { this.state = {
enabled, enabled,
@ -242,6 +244,7 @@ class SnippetEditor extends Component<SnippetEditorProps, SnippetEditorState> {
markdown, markdown,
name, name,
position, position,
shortcut,
toBeRemoved: false, toBeRemoved: false,
}; };
} }
@ -277,14 +280,22 @@ class SnippetEditor extends Component<SnippetEditorProps, SnippetEditorState> {
save = async () => { save = async () => {
let {snippet} = this.props; let {snippet} = this.props;
const {enabled, inDropdown, markdown, name, position, toBeRemoved} = const {
this.state; enabled,
inDropdown,
markdown,
name,
position,
shortcut,
toBeRemoved,
} = this.state;
snippet.value.enabled = enabled; snippet.value.enabled = enabled;
snippet.value.inDropdown = inDropdown; snippet.value.inDropdown = inDropdown;
snippet.value.markdown = markdown; snippet.value.markdown = markdown;
snippet.value.name = name; snippet.value.name = name;
snippet.value.position = position; snippet.value.position = position;
snippet.value.shortcut = shortcut;
const isBuiltin = snippet.value.id < 0; const isBuiltin = snippet.value.id < 0;
if (isBuiltin || toBeRemoved) { if (isBuiltin || toBeRemoved) {
@ -327,6 +338,7 @@ class SnippetEditor extends Component<SnippetEditorProps, SnippetEditorState> {
markdown, markdown,
name, name,
position, position,
shortcut,
toBeRemoved, toBeRemoved,
} = this.state; } = this.state;
@ -376,6 +388,17 @@ class SnippetEditor extends Component<SnippetEditorProps, SnippetEditorState> {
}} }}
/> />
<input
class="snippet-shortcut"
placeholder="Shortcut"
title="Shortcut"
type="text"
value={shortcut}
onInput={(event) => {
onEdit(event, "shortcut");
}}
/>
<label class="snippet-enabled"> <label class="snippet-enabled">
Enable{" "} Enable{" "}
<input <input

View File

@ -139,7 +139,7 @@
.top-controls { .top-controls {
display: grid; display: grid;
gap: 8px; gap: 8px;
grid-template-columns: 6rem auto max-content max-content; grid-template-columns: 6rem auto 9rem max-content max-content;
margin-bottom: 8px; margin-bottom: 8px;
} }

View File

@ -23,6 +23,9 @@ export type MarkdownSnippet = {
/** The position of the snippet in the toolbar. */ /** The position of the snippet in the toolbar. */
position: number; position: number;
/** The keyboard shortcut for this snippet. */
shortcut?: string;
}; };
/** /**