getSelection() returns a string instead of Selection object

Tobias Anton TA at ESC-Electronics.de
Tue Jun 8 11:51:20 BST 2004


On Freitag, 4. Juni 2004 19:16, Nick Swerdlow wrote:
> Hello all,
>
>
>
> I am trying to create a DOM Range object based off a user's selection.
>
> In Mozilla I can easily do this using:
> window.getSelection().getRangeAt(0)
> In IE I can do document.selection.createRange();
>
> However, in Konqueror(3.2.2) document.getSelection() returns a string
> instead of a Selection object and window.getSelection() doesn't work at
> all.

The current implementation does not support a "selection" object.

Excuse my lame question, but does ECMA define what kind of object the 
selection object is? Is it a DOM Range object?

If you know, please post a URL pointing to the location where this is 
specified.

Here is the relevant code block of KHTML:

  case HTMLDocument::GetSelection: {
    // NS4 and Mozilla specific. IE uses document.selection.createRange()
    // http://docs.sun.com/source/816-6408-10/document.htm#1195981
    KHTMLView *view = static_cast<DOM::DocumentImpl*>(doc.handle())->view();
    if ( view && view->part() )
       return String(view->part()->selectedText());
    else
       return Undefined();
  }



It would be fairly easy to replace
       return String(view->part()->selectedText());
by
	return DOMRange(exec, view->part()->selection());
But then, the JavaScript code
> window.getSelection().getRangeAt(0)
would not work, because the getSelection()-call would return the range that is 
expected to be returned by getRangeAt(0).

So I assume a special Selection-class would be needed, and to implement it, 
its interface requirements must be known.



> I know that the KHTML function KHTMLPart::selection() returns a
> DOM::Range object
> (http://developer.kde.org/documentation/library/2.0-api/classref/khtml/K
> HTMLPart.html#selection)
>
> The question is, is this function somehow exposed through JavaScript?
Not yet. See above for a possible approach.

> If not, does anyone know of a workaround for the problem?
Implement the selection()-object. Do you want to do this? We'd greatly 
appreciate it :-) If you need help, don't hesitate to post to this list.

Cheers
-- Tobias




More information about the kfm-devel mailing list