Skip to content
This repository has been archived by the owner on May 20, 2024. It is now read-only.

created keyboard shortcuts #2715

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 43 additions & 4 deletions src/utils/components/MarkdownInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
<QIcon :name="icon" />
</template>
<template #hint>
<div
class="row markdown-helper"
>
<div class="row markdown-helper">
<span class="text-bold">**{{ $t('MARKDOWN_INPUT.BOLD') }}**</span>
<span class="text-italic">_{{ $t('MARKDOWN_INPUT.ITALIC') }}_</span>
<span>~~<s>{{ $t('MARKDOWN_INPUT.STRIKE') }}</s>~~</span>
Expand Down Expand Up @@ -133,10 +131,51 @@ export default {
show: false,
}
},
mounted () {
this.$refs.input.$el.addEventListener('keydown', this.handleKeydown)
},
beforeUnmount () {
this.$refs.input.$el.removeEventListener('keydown', this.handleKeydown)
},
methods: {
handleKeydown (event) {
const { key, ctrlKey, altKey, shiftKey } = event
if (ctrlKey && key.toLowerCase() === 'b') {
this.applyMarkdown('**', '**')
event.preventDefault()
}
else if (ctrlKey && key.toLowerCase() === 'i') {
this.applyMarkdown('_', '_')
event.preventDefault()
}
else if (ctrlKey && key.toLowerCase() === 'u') {
this.applyMarkdown('<u>', '</u>')
event.preventDefault()
}
else if ((altKey && shiftKey && key === '5') || (ctrlKey && altKey && key === '5')) {
this.applyMarkdown('~~', '~~')
event.preventDefault()
}
},
applyMarkdown (prefix, suffix) {
const textArea = this.$refs.input.$el
const start = textArea.selectionStart
const end = textArea.selectionEnd
const selectedText = textArea.value.substring(start, end)
const beforeText = textArea.value.substring(0, start)
const afterText = textArea.value.substring(end)

const newText = beforeText + prefix + selectedText + suffix + afterText
this.$emit('update:modelValue', newText)
this.$nextTick(() => {
textArea.selectionStart = start + prefix.length
textArea.selectionEnd = end + prefix.length
textArea.focus()
})
},
onApplyMentions () {
// It loses focus when you click the mention menu without this
const input = this.$refs.input
const input = this.$refs.input.$el
if (!input) return
requestAnimationFrame(() => {
input.focus()
Expand Down