Question

I'm trying to write a text editor.

I'd need to:

  • be able to understand what text is selected so that a shortcut could work in the correct portion of text, just like in this editor, if I select a word in the middle of the text and then press Ctrl+B
  • Be able to catch when some keys are pressed like this Ctrl+B and TAB

any hint?

No correct solution

OTHER TIPS

Take a look at Reverse Engineering the WMD Editor. That's the editor used on SO and supports what you're referring to. The function that augments the current text selection as Bold is called doBorI(). Search for it in the source.

As for catching keyboard events, this page has a great primer on that, including detecting which key has been pressed.

Not sure what your specific question is exactly, but hopefully those are good starts.

I would suggest having a look at one of the existing editors to see how they handle this.

I recently started using: JWysiwyg, which has the advantage of being a very concise code-base and hence easier to decipher.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top