From 821d5eaea2fa1cc3e01808229ce415cc4f3bf95b Mon Sep 17 00:00:00 2001 From: Adam DeHaven Date: Wed, 27 Dec 2023 12:58:10 -0500 Subject: [PATCH] chore: add comments --- src/composables/useKeyboardShortcuts.ts | 2 ++ src/composables/useMarkdownActions.ts | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/composables/useKeyboardShortcuts.ts b/src/composables/useKeyboardShortcuts.ts index c449c0a0..2acbc224 100644 --- a/src/composables/useKeyboardShortcuts.ts +++ b/src/composables/useKeyboardShortcuts.ts @@ -90,6 +90,8 @@ export default function useKeyboardShortcuts( if (e.key && e.key === 'Tab') { getTextSelection() + // Require an active text selection to bind a tab or shift+tab + // This configuration passes the ["no keyboard trap"](https://www.w3.org/TR/WCAG21/#no-keyboard-trap) criterion of the W3C Web Content Accessibility Guidelines if (selectedText.text) { e.preventDefault() if (e.shiftKey) { diff --git a/src/composables/useMarkdownActions.ts b/src/composables/useMarkdownActions.ts index 030f38bc..243aa29c 100644 --- a/src/composables/useMarkdownActions.ts +++ b/src/composables/useMarkdownActions.ts @@ -133,6 +133,7 @@ export default function useMarkdownActions( // Always focus back on the textarea await focusTextarea() + // Set the cursor position textarea.selectionEnd = selectedText.start - wrapperLength return @@ -233,6 +234,7 @@ export default function useMarkdownActions( return } + // If some text is selected if (selectedText.text.length !== 0) { // Count number of line breaks in selection. Only include a single `\n` or the last of `\n\n` lineBreakCount = (selectedText.text.match(/\n(?!\n)/g) || []).length