Skip to content

Commit

Permalink
Skip checking for disabled keyboard actions in text-editor app (#9699)
Browse files Browse the repository at this point in the history
* Skip checking for disabled keyboard actions in text-editor app

* Implement feedback from code review

* Fix unit test
  • Loading branch information
pascalwengerter authored Sep 18, 2023
1 parent 7d93b94 commit b6041ce
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 2 additions & 0 deletions changelog/unreleased/enhancement-app-templates
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ This enables developers to more easily create custom apps, and brings unified be
https://github.com/owncloud/web/issues/9302
https://github.com/owncloud/web/issues/9303
https://github.com/owncloud/web/issues/9617
https://github.com/owncloud/web/issues/9695
https://github.com/owncloud/web/pull/9485
https://github.com/owncloud/web/pull/9699
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ export default defineComponent({
autosaveIntervalId = null
})
const { bindKeyAction } = useKeyboardActions()
const { bindKeyAction } = useKeyboardActions({ skipDisabledKeyBindingsCheck: true })
bindKeyAction({ modifier: ModifierKey.Ctrl, primary: Key.S }, () => {
if (!unref(isDirty)) {
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { useEventListener } from '@vueuse/core'
import { Ref, ref, unref } from 'vue'
import * as uuid from 'uuid'

interface KeyboardActionsOptions {
skipDisabledKeyBindingsCheck?: boolean
}

export enum Key {
C = 'c',
V = 'v',
Expand Down Expand Up @@ -65,12 +69,12 @@ const areCustomKeyBindingsDisabled = () => {
return isTextSelected
}

export const useKeyboardActions = (): KeyboardActions => {
export const useKeyboardActions = (options?: KeyboardActionsOptions): KeyboardActions => {
const actions = ref<Array<KeyboardAction>>([])
const selectionCursor = ref(0)

const listener = (event: KeyboardEvent): void => {
if (areCustomKeyBindingsDisabled()) {
if (!options?.skipDisabledKeyBindingsCheck && areCustomKeyBindingsDisabled()) {
return
}

Expand All @@ -81,6 +85,7 @@ export const useKeyboardActions = (): KeyboardActions => {
} else if (shiftKey) {
modifier = ModifierKey.Shift
}

unref(actions)
.filter((action) => {
return action.primary === key && action.modifier === modifier
Expand Down

0 comments on commit b6041ce

Please sign in to comment.