-
Notifications
You must be signed in to change notification settings - Fork 199
feat: add util function for common keyboard event handling #715
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
91c7769
db5b908
12a1346
d07a208
88d5bbb
2bda4bc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -517,6 +517,38 @@ const KeyCode = { | |||||||||||||||||||||||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| shouldIgnoreKeyboardEvent: function shouldIgnoreKeyboardEvent( | ||||||||||||||||||||||||||||||||||||||||||||||
| e: KeyboardEvent, | ||||||||||||||||||||||||||||||||||||||||||||||
| options?: { | ||||||||||||||||||||||||||||||||||||||||||||||
| checkEditable?: boolean; | ||||||||||||||||||||||||||||||||||||||||||||||
| checkComposing?: boolean; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. editable 应该是默认的,所以不需要这个参数。额外 compsing 检查就行了,不需要 |
||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major 补充 JSDoc 文档说明。 此函数作为新增的公共 API,应与文件中其他函数保持一致,添加 JSDoc 注释。建议说明函数用途、参数含义和返回值(例如:返回 🔎 建议的 JSDoc 文档+ /**
+ * Determines whether a keyboard event should be ignored based on the event target and composition state.
+ * @param e - The keyboard event to check
+ * @param options - Optional configuration
+ * @param options.checkEditable - Whether to ignore events on editable elements (default: true)
+ * @param options.checkComposing - Whether to ignore events during IME composition (default: true)
+ * @returns true if the event should be ignored, false otherwise
+ */
shouldIgnoreKeyboardEvent: function shouldIgnoreKeyboardEvent(
e: KeyboardEvent,
options?: {
checkEditable?: boolean;
checkComposing?: boolean;
},
) {📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||
| const target = e.target; | ||||||||||||||||||||||||||||||||||||||||||||||
| const { checkEditable = true, checkComposing = true } = options || {}; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| if (!(target instanceof HTMLElement)) { | ||||||||||||||||||||||||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| const tagName = target.tagName; | ||||||||||||||||||||||||||||||||||||||||||||||
| if ( | ||||||||||||||||||||||||||||||||||||||||||||||
| checkEditable && | ||||||||||||||||||||||||||||||||||||||||||||||
| (tagName === 'INPUT' || | ||||||||||||||||||||||||||||||||||||||||||||||
| tagName === 'TEXTAREA' || | ||||||||||||||||||||||||||||||||||||||||||||||
| tagName === 'SELECT' || | ||||||||||||||||||||||||||||||||||||||||||||||
| target.isContentEditable) | ||||||||||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| return true; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| if (checkComposing && e.isComposing) { | ||||||||||||||||||||||||||||||||||||||||||||||
| return true; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+529
to
+538
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| export default KeyCode; | ||||||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.