from caret to textRange object

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • gm1974

    #1

    from caret to textRange object

    Hi all,

    in a DHTML Editing control (MSIE), I need to "extend" the caret to the
    nearest text character in order to obtain a text selection (and than a
    textRange object with the createRange method).

    This is needed because I have a set of functions doing operations
    within the edit control's rich text. But all the functions need to
    start from a selected text (for example, adding a table row). My aim is
    to get the things work also if no text is selected from the user. But I
    could not find a way to have a selected text starting from the simple
    cursor position. Any suggestion?

    many thanks,

    giovanni

  • Baconbutty

    #2
    Re: from caret to textRange object

    Hi

    Hmm, not sure if this helps, or if I have understood correctly, but..

    My understanding is that "document.selec tion" represents the current
    selection or cursor position, and that a cursor is just a collapsed
    range (i.e. same start and end point)..

    http://msdn.microsoft.com/workshop/a...asp?frame=true

    Thus:-

    if (document.selec tion)
    {
    oCursorRange=do cument.selectio n.createRange() ;
    }

    You then use the MSIE TextRange methods

    e.g.

    oCursorRange.ex pand

    http://msdn.microsoft.com/workshop/a...ods/expand.asp

    You can also do this:-

    oCursorRange.co llapse(true);// If you want to make sure it is
    collapsed.

    Does this help?

    Julian

    Comment

    Working...