-
Notifications
You must be signed in to change notification settings - Fork 84
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 missing style transfer from existing textarea to hwt containers #19
base: master
Are you sure you want to change the base?
Conversation
Thanks for this, I like the idea. Some concerns though. It doesn't play well with existing CSS. For example, on the demo page: I'd like the solution to be backwards compatible. I don't know if that's feasible to do automatically, or if we put your code behind an option that people enable? Not sure. Also not sure about which styles are copied from the I'll keep thinking on it, would be sweet to make this work. |
jquery.highlight-within-textarea.css
Outdated
@@ -29,10 +29,8 @@ | |||
.hwt-input { | |||
display: block !important; | |||
position: relative !important; | |||
margin: 0; | |||
padding: 0; | |||
margin: 0 !important; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was margin left behind?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the original textarea had any margin set, it would be applied inside the .hwt-container, instead we want to add that amount of margin to the actual .hwt-container (so that it feels like the original textarea element) and remove any margin from the textarea inside
jquery.highlight-within-textarea.js
Outdated
}, | ||
|
||
getContainerDivCssFix: function(currentTextarea) { | ||
const textareaStyle = window.getComputedStyle(currentTextarea); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a performance hit with getComputedStyle
? Worth caching?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
jquery.highlight-within-textarea.js
Outdated
@@ -339,7 +371,7 @@ | |||
this.$backdrop.remove(); | |||
this.$el | |||
.unwrap() | |||
.removeClass(ID + '-text ' + ID + '-input') | |||
.removeClass(ID + '-content ' + ID + '-input') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
Couple of changes here. I believe users should not try to style Once you remove the custom |
I see your reasoning about it being an internal class, but this would still be a breaking change for current implementations. I would only consider breaking backwards compatibility for a new major version release, but I don't think it's ready for that. Still unsure how to determine all the properties that get copied and all the properties that don't. |
Hmmm, I suppose I also have a slightly different use case for the plugin. Currently, the styling of My use case is: I have a couple of textareas (potentially with various CSS styles) on a page and need to start highlighting their text at some point (call the highlight function). What my pull-request is trying to achieve is keeping the visual state the same before (without .hwt-* classes) and after the function is called (with .hwt-* classes). |
Ah, I see. That makes sense. |
Hi @Dalimil - sorry for bringing up such an old thread - but were you at all successful in applying the highlight without changing the original textfields? I need to do exactly that for this plug-in I'm developing, and I think your approach of styling the textarea based on existing attributes is the way to go. What did you mean however by "Once you remove the custom .hwt-content styles from the demo page (style textarea directly instead - simply change the CSS rule selector to update), it should work as expected with the new version."? I ask because after implementing your changes I am seeing the same bug (highlight is no longer matched to text -- the textfield now retains it's original style/position/etc however highlighting is off). Thanks for your time! |
@GrayedFox I believe I got it to work for my purposes, but it's been such a long time ago I honestly don't remember the code details... : https://github.com/Dalimil/highlight-within-textarea |
@Dalimil hey thanks for the reply, I ended up getting it working too, it was a matter of getting the padding and border values right (or more specifically, inheriting those from the textarea). Cheers :) |
This pull request fixes a couple of CSS bugs in the original plugin.
To exactly match our text overlay we must ensure that the two text containers have the same styling. For textareas that already have certain line-height and font CSS properties set, we must ensure that these are copied to our new containers, so that both text overlay perfectly.
This pull request also fixes previously transparent background - for dark (or any non-white) websites, this would modify the appearance of textareas and make them hard to read.