]> Untitled Git - lemmy-ui.git/commitdiff
Added Ctrl-K keybind
authorAdam Shea <davlyn.sheaa@outlook.com>
Fri, 9 Jun 2023 21:30:12 +0000 (21:30 +0000)
committerAdam Shea <davlyn.sheaa@outlook.com>
Fri, 9 Jun 2023 21:30:12 +0000 (21:30 +0000)
src/shared/components/common/markdown-textarea.tsx

index eff10d7275183471d8aab2020ae28a40aa0da1e1..efc812bfbe915235c84bdbc8b430e2ae89334b33 100644 (file)
@@ -148,6 +148,7 @@ export class MarkdownTextArea extends Component<
               value={this.state.content}
               onInput={linkEvent(this, this.handleContentChange)}
               onPaste={linkEvent(this, this.handleImageUploadPaste)}
+              onKeyDown={linkEvent(this, this.handleKeyBinds)}
               required
               disabled={this.isDisabled}
               rows={2}
@@ -429,6 +430,18 @@ export class MarkdownTextArea extends Component<
     i.contentChange();
   }
 
+  // Keybind handler
+  handleKeyBinds(i: MarkdownTextArea, event: KeyboardEvent) {
+    if (event.ctrlKey) {
+      switch (event.key) {
+        case "k": {
+          // Currently only one case but will support further keybinds
+          i.handleInsertLink(i, event);
+        }
+      }
+    }
+  }
+
   handlePreviewToggle(i: MarkdownTextArea, event: any) {
     event.preventDefault();
     i.setState({ previewMode: !i.state.previewMode });