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

Cursor position in FormattedInput #1257

Merged
merged 8 commits into from
Apr 14, 2022

Conversation

priyang12
Copy link
Contributor

@priyang12 priyang12 commented Mar 31, 2022

Fixes #1248

Technical details
Corrected Cursor Position using Diff package by creating a function.

Screenshots

Screen.Recording.2022-03-31.at.7.30.11.PM.mov

Checklist

  • My pull request has a descriptive title (not a vague title like Update index.md).
  • My pull request targets the master branch of the repository
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no
    visible errors.

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

@priyang12 priyang12 requested review from a team and pavish March 31, 2022 15:02
@codecov-commenter
Copy link

codecov-commenter commented Mar 31, 2022

Codecov Report

Merging #1257 (f65f6b8) into master (950724c) will not change coverage.
The diff coverage is n/a.

❗ Current head f65f6b8 differs from pull request most recent head 1771d29. Consider uploading reports for the commit 1771d29 to get more accurate results

@@           Coverage Diff           @@
##           master    #1257   +/-   ##
=======================================
  Coverage   93.46%   93.46%           
=======================================
  Files         114      114           
  Lines        4404     4404           
=======================================
  Hits         4116     4116           
  Misses        288      288           
Flag Coverage Δ
pytest-backend 93.46% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 950724c...1771d29. Read the comment docs.

@kgodey kgodey added the pr-status: review A PR awaiting review label Apr 1, 2022
@pavish
Copy link
Member

pavish commented Apr 6, 2022

@priyang12 Good job on this PR!

There is an edge case I noticed, when you edit a lengthy number (in the middle) which has a repeated number in it, eg.,100000000, the cursor position is not placed accurately.

However, before handling this, I am re-thinking the whole input. Here's the relevant discussion: #1268.

I'm placing the review and merge on hold until that discussion is resolved by the core team.

@pavish pavish added pr-status: revision A PR awaiting follow-up work from its author after review and removed pr-status: review A PR awaiting review labels Apr 6, 2022
@priyang12
Copy link
Contributor Author

@pavish ok thanks for the update.

@pavish
Copy link
Member

pavish commented Apr 11, 2022

The discussion #1268 is resolved.

@seancolsen I'm assigning you as the reviewer for this PR, since you've been the one working on the NumberInput component.

@pavish pavish assigned seancolsen and unassigned pavish Apr 11, 2022
@pavish pavish added pr-status: review A PR awaiting review and removed pr-status: revision A PR awaiting follow-up work from its author after review labels Apr 11, 2022
Copy link
Contributor

@seancolsen seancolsen left a comment

Choose a reason for hiding this comment

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

@priyang12 Thanks again for this PR.

For the most part, your work has improved the behavior of the input, so I'm merging this PR. However, as @pavish mentioned, there are some additional edge cases that we'll still need to handle. To track the work of handling those additional edge cases, I've opened #1284.

I pushed a commit to this PR which restructures your code as follows:

  • I renamed the function setCursorToPostion to getCursorPositionAfterReformat. That fixes the spelling error in "position" and makes the name more specific.
  • I made the function into a pure function and moved it to a utils file so that it's easier to test with unit tests.
  • I changed the argument structure to use named arguments with names that pertain to the purpose of the function instead of the purpose of the component. This increases readability when calling the function and reduces the risk of calling the function with the arguments mixed up.
  • I removed the TypeScript type any from within the function. We don't need to use it here. We should only use any as a last resort.
  • I made some other small naming changes within the function to increase readability.
  • I wrote a unit test with several test cases that pass. And I added more test cases that fail (with those test cases commented out.)
  • I removed the logic which checks to see if the last character is a number. We shouldn't need to do that. The process of setting the cursor position should work regardless of the characters in the text. One important reason is that the FormattedInput component is a general purpose component which serves as a building block for other components. So far, we only have NumberInput. But we may someday have others, like PhoneNumberInput or DateInput or CreditCardNumberInput. Further, within NumberInput specifically, sometimes the last character of the number isn't a digit. For example, we need to gracefully deal with an input of 12..

@seancolsen seancolsen enabled auto-merge April 14, 2022 12:57
@seancolsen seancolsen changed the title cursor position in FormattedInput PR #1248 Cursor position in FormattedInput Apr 14, 2022
@seancolsen seancolsen merged commit 8b1b02e into mathesar-foundation:master Apr 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-status: review A PR awaiting review
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

Retain cursor position when changing text within FormattedInput
5 participants