You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When typing by input method editor (IME) in a modal input (e.g. triggered by a Capture command), if enter is hit, the text is submitted immediately.
To Reproduce
Open omnisearch vault search command palette
Switch to an IME (most of them are CJK language)
Type something
Press enter, and the first file is opened
obsidian-omnisearch.mov
Here you can see I typed test in the IME, then I pressed enter, I intended to insert test in the input and continue typing, but the input was submitted and the file is opened.
Additional context
In CJK IME, when enter is hit, it means to insert the text without converting it to the CJK character, this is a common trick to insert English words without turning off the IME.
interfaceCompositionState{lock: boolean}exportfunctionlockInputMethodComposition(el: HTMLInputElement): CompositionState{conststate: CompositionState={lock: false,}el.addEventListener('compositionstart',()=>{state.lock=true})el.addEventListener('compositionend',()=>{state.lock=false})returnstate}constnameInputState=lockInputMethodComposition(nameInputEl)nameInputEl.addEventListener('keydown',async(e)=>{if(e.key==='Enter'&&!nameInputState.lock){e.preventDefault()// do things like submit the input here}})
Problem description:
When typing by input method editor (IME) in a modal input (e.g. triggered by a Capture command), if enter is hit, the text is submitted immediately.
To Reproduce
obsidian-omnisearch.mov
Here you can see I typed
test
in the IME, then I pressed enter, I intended to inserttest
in the input and continue typing, but the input was submitted and the file is opened.Additional context
In CJK IME, when enter is hit, it means to insert the text without converting it to the CJK character, this is a common trick to insert English words without turning off the IME.
By listening to Element: compositionstart event - Web APIs | MDN,
we can determine whether the enter key means to insert text or submit.
Here's a snippet I used in my projects:
Reference: dom events - What is JavaScript's CompositionEvent? Please give examples - Stack Overflow
Your environment:
The text was updated successfully, but these errors were encountered: