views:

78

answers:

2

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?

A: 

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.

Toby Hede
That very much complex than what I need, I'm not going to do a wysiwyg, and it will even be an editor for posts/comments. I need it for a particular language. I'd like to understand just how to do those 2 things. Anyway, if you say it's easy to read I'll have a look, thanks!
Andrea Ambu
+1  A: 

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.

Crescent Fresh