Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/KeyCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,38 @@ const KeyCode = {
return false;
}
},

shouldIgnoreKeyboardEvent: function shouldIgnoreKeyboardEvent(
Comment thread
aojunhao123 marked this conversation as resolved.
Outdated
e: KeyboardEvent,
options?: {
checkEditable?: boolean;
checkComposing?: boolean;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

editable 应该是默认的,所以不需要这个参数。额外 compsing 检查就行了,不需要 check 前缀。

},
) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

补充 JSDoc 文档说明。

此函数作为新增的公共 API,应与文件中其他函数保持一致,添加 JSDoc 注释。建议说明函数用途、参数含义和返回值(例如:返回 true 表示应忽略该键盘事件)。

🔎 建议的 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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
shouldIgnoreKeyboardEvent: function shouldIgnoreKeyboardEvent(
e: KeyboardEvent,
options?: {
checkEditable?: boolean;
checkComposing?: boolean;
},
) {
/**
* 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;
},
) {
🤖 Prompt for AI Agents
In src/KeyCode.ts around lines 521 to 527, the function
shouldIgnoreKeyboardEvent is missing JSDoc; add a JSDoc block immediately above
the function following the same style as other functions in this file that
explains the function purpose (determine whether a KeyboardEvent should be
ignored), describes parameters (e: KeyboardEvent; options object with optional
boolean checkEditable and checkComposing and what each flag does), and states
the return value (boolean — true means the event should be ignored). Include
@param annotations for each parameter and @returns describing the boolean
result.

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This conditional block can be simplified into a single return statement. This improves conciseness without sacrificing readability.

    return (
      e.isComposing ||
      tagName === 'INPUT' ||
      tagName === 'TEXTAREA' ||
      tagName === 'SELECT' ||
      target.isContentEditable
    );

},
};

export default KeyCode;
Loading