Desktop: Fixes #11485: Fix pressing enter during composition in the title input moves focus (#11491)

This commit is contained in:
Henry Heino
2024-12-12 22:30:20 +01:00
committed by GitHub
parent 30dbacc1a1
commit 421edb6691
@@ -85,7 +85,12 @@ export default function NoteTitleBar(props: Props) {
const onTitleKeydown: React.KeyboardEventHandler<HTMLInputElement> = useCallback((event) => {
const titleElement = event.currentTarget;
const selectionAtEnd = titleElement.selectionEnd === titleElement.value.length;
if ((event.key === 'ArrowDown' && selectionAtEnd) || (event.key === 'Enter' && !event.shiftKey)) {
const isNavigationShortcut = (event.key === 'ArrowDown' && selectionAtEnd) || (event.key === 'Enter' && !event.shiftKey);
const composing = event.nativeEvent.isComposing;
// Don't change focus if the navigation shortcut is fired during composition. See
// https://github.com/laurent22/joplin/issues/11485.
if (!composing && isNavigationShortcut) {
event.preventDefault();
const moveCursorToStart = event.key === 'ArrowDown';
void CommandService.instance().execute('focusElement', 'noteBody', { moveCursorToStart });