Multiple selection

1 view
Skip to first unread message

Adamantium

unread,
Dec 29, 2009, 8:14:42 AM12/29/09
to ubiquity-firefox
How would you do multiple selection in a text ( to be precise,
selection done using ctrl-select)

Blair McBride

unread,
Dec 29, 2009, 6:20:00 PM12/29/09
to ubiquity...@googlegroups.com
The Ubiquity API doesn't provide this, but the DOM API that Ubiquity
uses does. The key is selection.getRangeAt(x) - using different values
of x. selection.rangeCount has the number of ranges (areas that are
selected). So, assuming window is the content window:

var selection = window.getSelection();
var selectedTextParts = [];
for (var i = 0; i < selection.rangeCount; i++) {
var range = selection.getRangeAt(i);
selectedTextParts.push(range.toString());
}


See here for more complex uses, like getting the DOM nodes:
https://ubiquity.mozilla.com/hg/ubiquity-firefox/file/tip/ubiquity/modules/contextutils.js

- Blair

On 30/12/09 2:14 AM, Adamantium wrote:
> How would you do multiple selection in a text ( to be precise,
> selection done using ctrl-select)
>

> --
>
> You received this message because you are subscribed to the Google Groups "ubiquity-firefox" group.
> To post to this group, send email to ubiquity...@googlegroups.com.
> To unsubscribe from this group, send email to ubiquity-firef...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/ubiquity-firefox?hl=en.
>
>

Adamantium

unread,
Dec 30, 2009, 4:46:03 AM12/30/09
to ubiquity-firefox
Thanks. It's a bit confusing when there seem to be so many
api's ( ubiquity, fuel, dom, maybe xpcom? ) and you don't know what to
use.
In this case it's just plain dom isn't it?


On Dec 30, 4:20 am, Blair McBride <unfocu...@gmail.com> wrote:
> The Ubiquity API doesn't provide this, but the DOM API that Ubiquity
> uses does. The key is selection.getRangeAt(x) - using different values
> of x. selection.rangeCount has the number of ranges (areas that are
> selected). So, assuming window is the content window:
>
> var selection = window.getSelection();
> var selectedTextParts = [];
> for (var i  = 0; i < selection.rangeCount; i++) {
>    var range = selection.getRangeAt(i);
>    selectedTextParts.push(range.toString());
>
> }
>

> See here for more complex uses, like getting the DOM nodes:https://ubiquity.mozilla.com/hg/ubiquity-firefox/file/tip/ubiquity/mo...

Blair McBride

unread,
Dec 30, 2009, 6:48:29 AM12/30/09
to ubiquity...@googlegroups.com
On 30/12/09 10:46 PM, Adamantium wrote:
> In this case it's just plain dom isn't it?

Yep.

Ubiquity tries to wrap the most used parts various base APIs you
mentioned, but of course it can't do everything :)

- Blair

Reply all
Reply to author
Forward
0 new messages