Skip to content

perf: Optimize pressing enter to line breaks on mobile#2692

Merged
wangdan-fit2cloud merged 1 commit intomainfrom
pr@main/mobile-enter
Mar 26, 2025
Merged

perf: Optimize pressing enter to line breaks on mobile#2692
wangdan-fit2cloud merged 1 commit intomainfrom
pr@main/mobile-enter

Conversation

@wangdan-fit2cloud
Copy link
Copy Markdown
Contributor

What this PR does / why we need it?

Summary of your change

Please indicate you've done the following:

  • Made sure tests are passing and test coverage is added if needed.
  • Made sure commit message follow the rule of Conventional Commits specification.
  • Considered the docs impact and opened a new docs issue or PR with docs changes if needed.

@f2c-ci-robot
Copy link
Copy Markdown

f2c-ci-robot bot commented Mar 26, 2025

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@f2c-ci-robot
Copy link
Copy Markdown

f2c-ci-robot bot commented Mar 26, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@wangdan-fit2cloud wangdan-fit2cloud merged commit ca12d65 into main Mar 26, 2025
4 checks passed
@wangdan-fit2cloud wangdan-fit2cloud deleted the pr@main/mobile-enter branch March 26, 2025 08:00
}
if (!event?.ctrlKey && !event?.shiftKey && !event?.altKey && !event?.metaKey) {
// 如果没有按下组合键,则会阻止默认事件
event?.preventDefault()
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.

The provided code contains no major irregularities or critical issues. However, there are a few minor enhancements that could be made to improve readability and functionality:

  1. Function Name Clarity: The function name autoSendMessage suggests it's meant to handle auto-sending messages, but you might want to clarify its purpose with comments if it serves multiple roles.

  2. Event Object Checking: Adding an additional check before attempting to access properties of event can ensure better type safety and prevent errors. For example:

    if (event && typeof event.preventDefault !== 'function') {
      return;
    }
  3. Code Reformatting: Ensure consistent indentation and whitespace to make the code easier to read. This improves maintainability.

Here's the revised version of the function with these improvements:

function autoSendMessage() {
    // Functionality placeholder for automatic message sending logic here...
}

function sendChatHandle(event?: any): void {
    const isMobile = /Mobi|Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
    
    if ((isMobile || mode === 'mobile') && event?.key === 'Enter') {
        event?.preventDefault();
        return;
    }

    if (
        event &&
        typeof event.preventDefault === 'function' &&
        !event.ctrlKey &&
        !event.shiftKey &&
        !event.altKey &&
        !event.metaKey
    ) {
        event?.preventDefault();
    } else {
        console.warn("Invalid input detected; default action prevented.");
    }
}

These changes help make the code more robust and easier to understand. If the intention behind preventing certain actions remains unchanged, the current approach works well, so only the formatting and some optional checks have been added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants