-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Only set white-space on mirrored div for textareas #52
base: master
Are you sure you want to change the base?
Only set white-space on mirrored div for textareas #52
Conversation
852305e
to
3be9314
Compare
A white-space: nowrap would collapse spaces, but this won't happen on input fields. Try:
It will always display 5 spaces, no matter of the white-space-property. The pre is required as the mirror would otherwise use 'normal' and with a white-space: normal it may ignore multiple spaces and so on. With white-space: pre it won't break at all and will handle multiple spaces correctly for input fields. This should be added after the style-prop-loop: if (isInput) // force pre instead of pre-wrap on the input mirror
style.whiteSpace = 'pre'; Greetings |
@anotherCoward good call. Updated and pushed. |
I changed a lot more, at the time i required this snippet. Test around here http://jsfiddle.net/anotherCoward/sezkrm2c/ Added some options, like getting the absolute/relative position and support for almost any text-element (like Changes
UsagegetCaretCoordinates(element, position, options);element [optional] HTMLElement
position [optional] numberNote: This value will be ignored on HTMLElements except input/textarea
options [optional] object
Known Issues
There might be some more issues and things i forgot to mention and i had a some trouble with Edge at that time (like no scrollLeft-values on Edges input elements) - but as Edge switched to Chromium Engine the checks for Edge could be removed. Greetings |
@anotherCoward sorry it has taken a while to respond to this. The changes you posted certainly resolve my issue and would make this PR unnecessary. Will these changes be published/committed any time soon? |
@schinizel I think the changes live on their fork see https://github.com/anotherCoward/textarea-caret-position. I'm not sure if @anotherCoward has ever published their new version to npm though. |
I have never published it, but feel free to use it. If it helps. =) |
This addresses an issue with incorrect top coordinates being returned in cases where the mirrored div wraps hyphenated text.
See issue #51 for context. By only applying the
white-space
property totextarea
and notinput
it allows people to set awhite-space: nowrap
on the element if we need it. I debated setting it explicitly (since inputs never wrap) but it seemed better to simply allow people to control the property on their own.