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

Easy way to implement highlight with a bg color and changing font color? #62

Open
pjfsilva opened this issue Sep 4, 2015 · 2 comments

Comments

@pjfsilva
Copy link

pjfsilva commented Sep 4, 2015

I have a textarea where I want to highlight some text to have a black background and white font color for that words.

I've thought a bit about this and looked into a lot of jquery highlight textarea plugins and it seems this it really not a trivial task...
I could use a full featured text editor like Ace but that's really a bit too much for my needs :)

Anyone has any ideas how to achieve this easily?

@pjfsilva
Copy link
Author

pjfsilva commented Sep 4, 2015

I can contribute a bit further on my ideas:

  • One alternative is to remove the textarea and just a div with contenteditable. That has some drawbacks because then you have to parse the HTML on the backend to remove it and just get the text. Another one is if people copy-paste rich text (with images for example) they will pasted as rich text and not just plain text
  • setting a higher z-index on the highlighter div and setting the textarea with a lower z-index and color transparent. Problem here is the text "caret" also becomes transparent which is really no good. [you can add a text caret with more JS code: http://stackoverflow.com/questions/11516736/how-to-have-transparent-fonts-except-for-the-text-caret-in-a-textarea ]
  • just removing the textarea text and use just the text on the highlighter div. Problem here is the text cursor would not be at the correct place...

@alariva
Copy link

alariva commented Dec 25, 2015

👍 Met the same need

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

No branches or pull requests

2 participants