Skip to content
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

fix(InputMask): Paste at Cursor Selection #5286

Merged
merged 5 commits into from
Nov 13, 2023

Conversation

Triggs125
Copy link
Contributor

@Triggs125 Triggs125 commented Nov 10, 2023

The input mask component currently pastes contents at the first empty value position instead of the cursor selection. Providing an undefined position to the caret function mostly fixes this issue because after the paste happens, the cursor is returned to the last empty value position instead of at the end of the newly pasted value.

Defect Fixes

Fix #5285

Copy link

vercel bot commented Nov 10, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
primereact ⬜️ Ignored (Inspect) Visit Preview Nov 13, 2023 2:48pm

Copy link

Thanks a lot for your contribution! But, PR does not seem to be linked to any issues. Please manually link to an issue or mention it in the description using #<issue_id>.

@melloware melloware added the Type: Bug Issue contains a defect related to a specific component. label Nov 10, 2023
@melloware
Copy link
Member

thanks @Triggs125 looks good to me but assigned to PrimeTek for testing before merging.

@nitrogenous
Copy link
Contributor

nitrogenous commented Nov 10, 2023

Thank you for addressing this and your contribution. I just took quick view to your code. I will be reviewing and testing it more detailed asap.

Copy link
Contributor

@nitrogenous nitrogenous left a comment

Choose a reason for hiding this comment

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

Hey @Triggs125 I reviewed your contribution it looks good but I think we can add one extra parameter to handleInputChange function to prevent code duplication. I have tried this version and it seems working properly. What do you say??

const handleInputChange = (e, isOnPaste = false) => {
    if (props.readOnly) {
        return;
    }

    if (!isOnPaste) {
        let pos = checkVal(true);

        caret(pos);
    }

    updateModel(e);

    if (props.onComplete && isCompleted()) {
        props.onComplete({
            originalEvent: e,
            value: getValue()
        });
    }
};
onPaste={(e) => handleInputChange(e, true)}

@nitrogenous nitrogenous self-requested a review November 13, 2023 08:12
@melloware
Copy link
Member

I agree with @nitrogenous

@melloware
Copy link
Member

Run npm run format to fix your formatting issues.

The input mask component currently pastes contents at the first empty value position instead of the cursor selection. Providing an undefined position to the caret function *mostly* fixes this issue because after the paste happens, the cursor is returned to the last empty value position instead of at the end of the newly pasted value.
@melloware melloware merged commit 02f78ab into primefaces:master Nov 13, 2023
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a defect related to a specific component.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

InputMask: Pasting does not respect the cursor selection
4 participants