mirror of
https://github.com/go-gitea/gitea.git
synced 2026-05-15 15:03:32 +02:00
Prevent navigation keys from triggering actions during IME composition (#36540)
Fixes #36532 Refined the Enter key trigger logic in the repository filter to prevent actions during IME composition. By checking the e.isComposing property, the filter now correctly distinguishes between "confirming an IME candidate" and "submitting the search." This prevents premature search triggers when users press Enter to select Chinese/Japanese characters. --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
parent
a60201a071
commit
ef529de0ac
@ -307,6 +307,7 @@ export default defineComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
async reposFilterKeyControl(e: KeyboardEvent) {
|
async reposFilterKeyControl(e: KeyboardEvent) {
|
||||||
|
if (e.isComposing) return;
|
||||||
switch (e.key) {
|
switch (e.key) {
|
||||||
case 'Enter':
|
case 'Enter':
|
||||||
document.querySelector<HTMLAnchorElement>('.repo-owner-name-list li.active a')?.click();
|
document.querySelector<HTMLAnchorElement>('.repo-owner-name-list li.active a')?.click();
|
||||||
|
|||||||
@ -159,6 +159,7 @@ export default defineComponent({
|
|||||||
return el?.length ? el[0] : null;
|
return el?.length ? el[0] : null;
|
||||||
},
|
},
|
||||||
keydown(e: KeyboardEvent) {
|
keydown(e: KeyboardEvent) {
|
||||||
|
if (e.isComposing) return;
|
||||||
if (e.key === 'ArrowUp' || e.key === 'ArrowDown') {
|
if (e.key === 'ArrowUp' || e.key === 'ArrowDown') {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
|
|||||||
@ -42,6 +42,8 @@ const handleSearchInput = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleKeyDown = (e: KeyboardEvent) => {
|
const handleKeyDown = (e: KeyboardEvent) => {
|
||||||
|
if (e.isComposing) return;
|
||||||
|
|
||||||
if (e.key === 'Escape') {
|
if (e.key === 'Escape') {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
clearSearch();
|
clearSearch();
|
||||||
|
|||||||
@ -14,6 +14,7 @@ export function initGlobalFormDirtyLeaveConfirm() {
|
|||||||
|
|
||||||
export function initGlobalEnterQuickSubmit() {
|
export function initGlobalEnterQuickSubmit() {
|
||||||
document.addEventListener('keydown', (e) => {
|
document.addEventListener('keydown', (e) => {
|
||||||
|
if (e.isComposing) return;
|
||||||
if (e.key !== 'Enter') return;
|
if (e.key !== 'Enter') return;
|
||||||
const hasCtrlOrMeta = ((e.ctrlKey || e.metaKey) && !e.altKey);
|
const hasCtrlOrMeta = ((e.ctrlKey || e.metaKey) && !e.altKey);
|
||||||
if (hasCtrlOrMeta && (e.target as HTMLElement).matches('textarea')) {
|
if (hasCtrlOrMeta && (e.target as HTMLElement).matches('textarea')) {
|
||||||
|
|||||||
@ -223,6 +223,7 @@ function isTextExpanderShown(textarea: HTMLElement): boolean {
|
|||||||
|
|
||||||
export function initTextareaMarkdown(textarea: HTMLTextAreaElement) {
|
export function initTextareaMarkdown(textarea: HTMLTextAreaElement) {
|
||||||
textarea.addEventListener('keydown', (e) => {
|
textarea.addEventListener('keydown', (e) => {
|
||||||
|
if (e.isComposing) return;
|
||||||
if (isTextExpanderShown(textarea)) return;
|
if (isTextExpanderShown(textarea)) return;
|
||||||
if (e.key === 'Tab' && !e.ctrlKey && !e.metaKey && !e.altKey) {
|
if (e.key === 'Tab' && !e.ctrlKey && !e.metaKey && !e.altKey) {
|
||||||
// use Tab/Shift-Tab to indent/unindent the selected lines
|
// use Tab/Shift-Tab to indent/unindent the selected lines
|
||||||
|
|||||||
@ -82,6 +82,7 @@ function initRepoIssueLabelFilter(elDropdown: HTMLElement) {
|
|||||||
});
|
});
|
||||||
// alt(or option) + enter to exclude selected label
|
// alt(or option) + enter to exclude selected label
|
||||||
elDropdown.addEventListener('keydown', (e: KeyboardEvent) => {
|
elDropdown.addEventListener('keydown', (e: KeyboardEvent) => {
|
||||||
|
if (e.isComposing) return;
|
||||||
if (e.altKey && e.key === 'Enter') {
|
if (e.altKey && e.key === 'Enter') {
|
||||||
const selectedItem = elDropdown.querySelector('.label-filter-query-item.selected');
|
const selectedItem = elDropdown.querySelector('.label-filter-query-item.selected');
|
||||||
if (selectedItem) excludeLabel(e, selectedItem);
|
if (selectedItem) excludeLabel(e, selectedItem);
|
||||||
|
|||||||
@ -225,6 +225,7 @@ function attachDomEvents(dropdown: HTMLElement, focusable: HTMLElement, menu: HT
|
|||||||
};
|
};
|
||||||
|
|
||||||
dropdown.addEventListener('keydown', (e: KeyboardEvent) => {
|
dropdown.addEventListener('keydown', (e: KeyboardEvent) => {
|
||||||
|
if (e.isComposing) return;
|
||||||
// here it must use keydown event before dropdown's keyup handler, otherwise there is no Enter event in our keyup handler
|
// here it must use keydown event before dropdown's keyup handler, otherwise there is no Enter event in our keyup handler
|
||||||
if (e.key === 'Enter') {
|
if (e.key === 'Enter') {
|
||||||
const elItem = menu.querySelector<HTMLElement>(':scope > .item.selected, .menu > .item.selected');
|
const elItem = menu.querySelector<HTMLElement>(':scope > .item.selected, .menu > .item.selected');
|
||||||
|
|||||||
@ -22,6 +22,7 @@ window.customElements.define('overflow-menu', class extends HTMLElement {
|
|||||||
const div = document.createElement('div');
|
const div = document.createElement('div');
|
||||||
div.tabIndex = -1; // for initial focus, programmatic focus only
|
div.tabIndex = -1; // for initial focus, programmatic focus only
|
||||||
div.addEventListener('keydown', (e) => {
|
div.addEventListener('keydown', (e) => {
|
||||||
|
if (e.isComposing) return;
|
||||||
if (e.key === 'Tab') {
|
if (e.key === 'Tab') {
|
||||||
const items = this.tippyContent.querySelectorAll<HTMLElement>('[role="menuitem"]');
|
const items = this.tippyContent.querySelectorAll<HTMLElement>('[role="menuitem"]');
|
||||||
if (e.shiftKey) {
|
if (e.shiftKey) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user