Brian King writes:
> The Task
> --------
> In the editor (specifically mail/news compose version), I am typing and 
> when I hit <SPACE> I want to traverse back and grab the last typed word.
[various ideas about using DOM Range to sniff out space]

Daniel Glazman writes:
> Akkana told me on IRC there are ways to extend the selection (probably
> reduced to the caret in your case) to the previous/next word.  Should be
> enough for what you need.

The relevant interface is nsISelectionController:
http://lxr.mozilla.org/seamonkey/source/content/base/public/nsISelectionController.idl

In particular, you want:
  void wordMove(in boolean forward, in boolean extend);

The editor uses wordMove for its motion commands, and key bindings for
character, word and line movements in both editor and browser call into
this interface.

The calls are fairly straightforward; they're used in a lot of editor
commands so you can find examples there, but feel free to ask if you
need more help on that.

But, you say, I don't want to move the current selection, I just
want to sniff out where the word ends while leaving the selection
untouched?

The selection controller has a concept of "SelectionType" which allows
you to have several different selections, not just the active one that
the user sees as the visible selection.  I'm a bit fuzzy on how this
works and I don't think it ever got documented :-( but it looks
like the list starting at line 42 with SELECTION_NORMAL is the list
of available types, and SELECTION_NORMAL is the visible one.
Some of the others will show up in various ways, and others may be
invisible (I think SELECTION_ACCESSIBILITY shows up depending on
caret mode, and SELECTION_SPELLCHECK might be underlined?) so you
may have to experiment, or look at the code (start with nsSelection.cpp
or else just lxr for particular selection types) to see what layout is
doing about visibility.  There seem to be a lot of special cases
(looks like they just got added one by one as people asked for them,
rather than being designed in an extensible way).

If you do spend any time chasing down which of these selection types
has which type of visibility, it would be great to have them documented
somewhere, even if it was just a comment in nsISelectionController.idl.

        ...Akkana
_______________________________________________
mozilla-editor mailing list
[EMAIL PROTECTED]
http://mail.mozilla.org/listinfo/mozilla-editor

Reply via email to