mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-03 11:19:10 +08:00
Fix slash newline (#10305)
* Fix slash menu Shift+Enter newline * fix: enable Shift+Enter newline in rich editor with slash commands Fixed an issue where users couldn't create new lines using Shift+Enter when slash command menu (/foo) was active. The problem was caused by globa keyboard event handlers intercepting all Enter key variants. Changes: - Allow Shift+Enter to pass through QuickPanel event handling - Add Shift+Enter detection in CommandListPopover to return false - Implement fallback Shift+Enter handling in command suggestion render - Remove unused import in AppUpdater.ts - Convert Chinese comments to English in QuickPanel - Add test coverage for command suggestion functionality --------- Co-authored-by: Zhaokun Zhang <zhaokunzhang@Zhaokuns-Air.lan>
This commit is contained in:
parent
b85040f579
commit
d41e239b89
@ -457,7 +457,13 @@ export const QuickPanelView: React.FC<Props> = ({ setInputText }) => {
|
|||||||
|
|
||||||
// 面板可见且未折叠时:拦截所有 Enter 变体;
|
// 面板可见且未折叠时:拦截所有 Enter 变体;
|
||||||
// 纯 Enter 选择项,带修饰键仅拦截不处理
|
// 纯 Enter 选择项,带修饰键仅拦截不处理
|
||||||
if (e.ctrlKey || e.metaKey || e.altKey || e.shiftKey) {
|
if (e.shiftKey && !e.ctrlKey && !e.metaKey && !e.altKey) {
|
||||||
|
// Don't prevent default or stop propagation - let it create a newline
|
||||||
|
setIsMouseOver(false)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
if (e.ctrlKey || e.metaKey || e.altKey) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
setIsMouseOver(false)
|
setIsMouseOver(false)
|
||||||
|
|||||||
@ -87,6 +87,9 @@ const CommandListPopover = ({
|
|||||||
return true
|
return true
|
||||||
|
|
||||||
case 'Enter':
|
case 'Enter':
|
||||||
|
if (event.shiftKey) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
if (items[internalSelectedIndex]) {
|
if (items[internalSelectedIndex]) {
|
||||||
selectItem(internalSelectedIndex)
|
selectItem(internalSelectedIndex)
|
||||||
|
|||||||
@ -0,0 +1,17 @@
|
|||||||
|
import { describe, expect, it } from 'vitest'
|
||||||
|
|
||||||
|
import { commandSuggestion } from '../command'
|
||||||
|
|
||||||
|
describe('commandSuggestion render', () => {
|
||||||
|
it('has render function', () => {
|
||||||
|
expect(commandSuggestion.render).toBeDefined()
|
||||||
|
expect(typeof commandSuggestion.render).toBe('function')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('render function returns object with onKeyDown', () => {
|
||||||
|
const renderResult = commandSuggestion.render?.()
|
||||||
|
expect(renderResult).toBeDefined()
|
||||||
|
expect(renderResult?.onKeyDown).toBeDefined()
|
||||||
|
expect(typeof renderResult?.onKeyDown).toBe('function')
|
||||||
|
})
|
||||||
|
})
|
||||||
@ -628,13 +628,34 @@ export const commandSuggestion: Omit<SuggestionOptions<Command, MentionNodeAttrs
|
|||||||
},
|
},
|
||||||
|
|
||||||
onKeyDown: (props) => {
|
onKeyDown: (props) => {
|
||||||
|
// Let CommandListPopover handle events first
|
||||||
|
const popoverHandled = component.ref?.onKeyDown?.(props.event)
|
||||||
|
if (popoverHandled) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle Shift+Enter for newline when popover doesn't handle it
|
||||||
|
if (props.event.key === 'Enter' && props.event.shiftKey) {
|
||||||
|
props.event.preventDefault()
|
||||||
|
// Close the suggestion menu
|
||||||
|
if (cleanup) cleanup()
|
||||||
|
component.destroy()
|
||||||
|
// Use the view from SuggestionKeyDownProps to insert newline
|
||||||
|
const { view } = props
|
||||||
|
const { state, dispatch } = view
|
||||||
|
const { tr } = state
|
||||||
|
tr.insertText('\n')
|
||||||
|
dispatch(tr)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
if (props.event.key === 'Escape') {
|
if (props.event.key === 'Escape') {
|
||||||
if (cleanup) cleanup()
|
if (cleanup) cleanup()
|
||||||
component.destroy()
|
component.destroy()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
return component.ref?.onKeyDown(props.event)
|
return false
|
||||||
},
|
},
|
||||||
|
|
||||||
onExit: () => {
|
onExit: () => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user