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 type when previous selection in input in some cases #5809

Merged
merged 5 commits into from Nov 27, 2019

Conversation

kuceb
Copy link
Contributor

@kuceb kuceb commented Nov 27, 2019

User facing changelog

  • fixes issue with .type not respecting previous selection in non-selectionRange input element (email, number) (only way to change selection is with .select())
  • fixes issue with .type not respecting previous selection if current value of the input is same as key

Additional details

  • code from firefox branch was pulled in, causing the large amount of files changed. This will help reduce changes needed for firefox as well

How has the user experience changed?

when attempting to use .type on a number or email input that has a text selection (or is selected in a focus handler):

before (incorrect): text is appended to the current selection
after (correct): text replaces current selection

when attempting to use .type on an input that has a text selection (or is selected in a focus handler) of 1 character equal to the key typed:

before (incorrect): ignores current key, next character replaces selection
after (correct): text replaces current selection, next character is typed after

PR Tasks

  • Have tests been added/updated?
  • Has the original issue been tagged with a release in ZenHub?

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Nov 27, 2019

Thanks for the contribution! Below are some guidelines Cypress uses when doing PR reviews.

  • Please write [WIP] in the title of your Pull Request if your PR is not ready for review - someone will review your PR as soon as the [WIP] is removed.
  • Please familiarize yourself with the PR Review Checklist and feel free to make updates on your PR based on these guidelines.

PR Review Checklist

If any of the following requirements can't be met, leave a comment in the review selecting 'Request changes', otherwise 'Approve'.

User Experience

  • The feature/bugfix is self-documenting from within the product.
  • The change provides the end user with a way to fix their problem (no dead ends).

Functionality

  • The code works and performs its intended function with the correct logic.
  • Performance has been factored in (for example, the code cleans up after itself to not cause memory leaks).
  • The code guards against edge cases and invalid input and has tests to cover it.

Maintainability

  • The code is readable (too many nested 'if's are a bad sign).
  • Names used for variables, methods, etc, clearly describe their function.
  • The code is easy to understood and there are relevant comments explaining.
  • New algorithms are documented in the code with link(s) to external docs (flowcharts, w3c, chrome, firefox).
  • There are comments containing link(s) to the addressed issue (in tests and code).

Quality

  • The change does not reimplement code.
  • There's not a module from the ecosystem that should be used instead.
  • There is no redundant or duplicate code.
  • There are no irrelevant comments left in the code.
  • Tests are testing the code’s intended functionality in the best way possible.

Internal

  • The original issue has been tagged with a release in ZenHub.

@cypress
Copy link

cypress bot commented Nov 27, 2019



Test summary

3520 0 45 0


Run details

Project cypress
Status Passed
Commit 1859d5c
Started Nov 27, 2019 8:15 PM
Ended Nov 27, 2019 8:19 PM
Duration 04:17 💡
OS Linux Debian - 9.8
Browser Multiple

View run in Cypress Dashboard ➡️


This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard

const curVal = $elements.getNativeProp(el, 'value')
const bounds = $selection.getSelectionBounds(el)

const potentialValue = $selection.insertSubstring(curVal + needsValue, key.text, [bounds.start + needsValueLength, bounds.end + needsValueLength])
Copy link
Member

Choose a reason for hiding this comment

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

i feel like this needs an explanation... its so opaque why this is necessary

e.currentTarget.select()
})

// input[0].setSelectionRange(0,0)
Copy link
Member

Choose a reason for hiding this comment

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

delete

return false
}

const getCaretPosition = function (el) {
const bounds = getSelectionBounds(el)

if (bounds.start == null) {
if ((bounds.start == null)) {
Copy link
Member

Choose a reason for hiding this comment

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

parenths

start: 0,
end: 0,
start: null,
end: null,
Copy link
Member

Choose a reason for hiding this comment

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

switch back to switch (true)

Copy link
Member

@brian-mann brian-mann left a comment

Choose a reason for hiding this comment

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

minor changes per my comments

Comment on lines 508 to 516
const isAttrType = function (el: HTMLInputElement, type: string) {
const elType = (el.getAttribute('type') || '').toLowerCase()

if (elType === type) {
return true
}

return false
}
Copy link
Member

Choose a reason for hiding this comment

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

.should('have.value', '10')
})

it('overwrites text when selectAll in focus handler in date', () => {
Copy link
Member

Choose a reason for hiding this comment

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

email not date

@flotwig flotwig merged commit bfb9d83 into develop Nov 27, 2019
flotwig added a commit that referenced this pull request Nov 27, 2019
avallete pushed a commit to avallete/cypress that referenced this pull request Nov 28, 2019
)

* fix type when previous selection in input

* cleanup

* cleanup more

* more cleanup

* more more cleanup final
avallete pushed a commit to avallete/cypress that referenced this pull request Nov 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3.5.0-3.6.1 regression - cy.type() may skip a character on a autofocussing textbox
3 participants