Modify the pop-up conditions of muya-format-picker

This commit is contained in:
cfs4819 2023-12-06 16:45:01 +08:00
parent b75895cdd1
commit c8803a7cb0
2 changed files with 12 additions and 1 deletions

View File

@ -55,7 +55,8 @@ export const EVENT_KEYS = Object.freeze(generateKeyHash([
'ArrowLeft', 'ArrowLeft',
'ArrowRight', 'ArrowRight',
'Tab', 'Tab',
'Escape' 'Escape',
'Shift'
])) ]))
export const LOWERCASE_TAGS = Object.freeze(generateKeyHash([ export const LOWERCASE_TAGS = Object.freeze(generateKeyHash([

View File

@ -8,6 +8,7 @@ class Keyboard {
constructor (muya) { constructor (muya) {
this.muya = muya this.muya = muya
this.isComposed = false this.isComposed = false
this.isShiftDown = false
this.shownFloat = new Set() this.shownFloat = new Set()
this.recordIsComposed() this.recordIsComposed()
this.dispatchEditorState() this.dispatchEditorState()
@ -187,6 +188,10 @@ class Keyboard {
case EVENT_KEYS.Tab: case EVENT_KEYS.Tab:
contentState.tabHandler(event) contentState.tabHandler(event)
break break
case EVENT_KEYS.Shift:
eventCenter.dispatch('muya-format-picker', { reference: null })
this.isShiftDown = true
break
default: default:
break break
} }
@ -252,6 +257,10 @@ class Keyboard {
}) })
} }
if (event.key === EVENT_KEYS.Shift) {
this.isShiftDown = false
}
const { anchor, focus, start, end } = selection.getCursorRange() const { anchor, focus, start, end } = selection.getCursorRange()
if (!anchor || !focus) { if (!anchor || !focus) {
return return
@ -276,6 +285,7 @@ class Keyboard {
const block = contentState.getBlock(anchor.key) const block = contentState.getBlock(anchor.key)
if ( if (
this.isShiftDown === false &&
anchor.key === focus.key && anchor.key === focus.key &&
anchor.offset !== focus.offset && anchor.offset !== focus.offset &&
block.functionType !== 'codeContent' && block.functionType !== 'codeContent' &&