RichTextArea - cursor position + selection length

87 views
Skip to first unread message

efree...@gmail.com

unread,
Oct 8, 2007, 8:49:16 AM10/8/07
to Google Web Toolkit
Hey,

I need to read cursor position and selection length in RichTextArea.
Any suggestions how to do this?

s4nTuZz0

unread,
Oct 8, 2007, 4:57:36 PM10/8/07
to Google Web Toolkit
Hi, i'm interested to your same questions. i've spent a lot of time
above, unsuccesfully. anyone can give us any help ? :-) thanks.

On Oct 8, 2:49 pm, "efreetm...@gmail.com" <efreetm...@gmail.com>
wrote:

Axel Kittenberger

unread,
Oct 8, 2007, 6:50:54 PM10/8/07
to Google Web Toolkit
While there is possible JSNI browser interface to determine a
selection, AFAIK the browser generally don't provide an interface to
get much of the cursor information. Firfox maybe has some XUL commands
for this, but thats it. Nevertheless I will seize the opportunity plug
my project AceArea -- http://code.google.com/p/acearea/ -- it's an
editor completly* writen in GWT, that does not use the browser
internal editor like almost all the editors including RichTextArea do,
but implements it all in javascript, this gives the coder absolute
control. However while it has gone a far way, and even is already
useable enough for me to use it myself, I cannot recommend it yet in a
production environment nor are RichText elements like bold, italics,
yet implemented....

*99% GWT, 1% JSNI

param

unread,
Oct 9, 2007, 1:30:52 AM10/9/07
to Google Web Toolkit
Hi Alex,

Good work ..
I am also interested in doing suck kind of think.If you want any help
let me know

thanks

On Oct 9, 3:50 am, Axel Kittenberger <axe...@gmail.com> wrote:
> While there is possible JSNI browser interface to determine a
> selection, AFAIK the browser generally don't provide an interface to
> get much of the cursor information. Firfox maybe has some XUL commands
> for this, but thats it. Nevertheless I will seize the opportunity plug

> my project AceArea --http://code.google.com/p/acearea/-- it's an

Md. Sohel

unread,
Oct 9, 2007, 2:17:29 AM10/9/07
to Google-We...@googlegroups.com
Hey
 
I also ased for the same question. Any one can help me?
 
 
Regards
Sohel
 

efree...@gmail.com

unread,
Oct 9, 2007, 8:46:20 AM10/9/07
to Google Web Toolkit
My Firefox-only solution (in IE it is easier to solve). Please let me
know if somebody finds nicer solution.


public native int getSelectionStart(Element elem)/*-{
return
elem.contentWindow.getSelection().getRangeAt(0).startOffset;
}-*/;

public native int getSelectionLength(Element elem)/*-{
return
elem.contentWindow.getSelection().getRangeAt(0).toString().length;
}-*/;

public native int getSelectionStartNode(Element elem)/*-{
var
node=elem.contentWindow.getSelection().getRangeAt(0).startContainer;
if(node.parentNode.nodeName != 'BODY')
{
node = node.parentNode;
}

var nodes = node.parentNode.childNodes;
i = 0;
while(node.previousSibling != null)
{
node = node.previousSibling;
i++;
}

return i;
}-*/;

Axel Kittenberger

unread,
Oct 9, 2007, 9:07:38 AM10/9/07
to Google Web Toolkit
Yes thats the way to do to get the selection info, I only dont
undestart why on getSelectionStartNode you start counting nodes, and
not retrieve the node as Element right away.
But as said AFAIK there is no interface to get/set the cursor
position.

On Oct 9, 2:46 pm, "efreetm...@gmail.com" <efreetm...@gmail.com>
wrote:

Axel Kittenberger

unread,
Oct 9, 2007, 9:30:07 AM10/9/07
to Google Web Toolkit
Oh, I am very glad if others are interested in this project. Infact I
just updated the source on google projects to reflect the latest
status, normally from day to day work I use a private local svn
repository.

I realize its difficult to drop into a alpha-status project, as oposed
to this in release state projects you normally start by using it, and
enhancing it for a specific need. Also its not my style to tell anyone
what to do, there are just so many things to change/enhance, in fact a
friend of mine every week he comes with another idea whats now
possible to do with this widget, what wasn't possible before. Right
now I'm working on block/selection/copy/paste/clipboard support,
together with an undo/redo machanism its IMHO the last step to be a
useful text editor at least.

Also important to note what I'm proud of, altough a monospaced font is
now default, is it works not only with monospaced fonts but also with
dynamic ones.
Things on the general TOWISH list are:
* Opera support (right now only the issues with Firefox and IE are
handled, I chose these 2 as the majority of the market, and not
depending on any browser specific enhancements)
* Safari support, I I have not right now easy access to a safari
browser, and well other reasons see opera.
* RichText support:
** Bold, Italic, Colored fonts, Links, Other font style/size etc.
** Table editing
** Inline picture support

on the other side than the WYSIWYG path is:
* a syntax highliting for diverse languages like java/javascript/c/
etc.
* spellchecking. Obviously we can't expect the client to hold the
dictionary, so a AJAX mechanism would make sense, having the server
checking spelling in background.
* Exception handling: bad stuff happens, it would be wishable to catch
all exceptions, and provide the user a feedback, why the application
stopped working properly, and having an option to try to retrieve his
work in progress.
* Integration of AceArea in wikipedia as user script
* optimize the cursor position finding algorithmn

and so on, generally I take "customizeable" seriously and constructed
the whole thing with an internal message handling, so it should be
able for users to extend without having to change the widget code
itself, however its alway possible to do so! As possible extensions I
have my own "big picture" of e.g. collaberative editing, wiki
integration in the editor etc.

also I try to take documentation seriously, starting with trying to do
good source code comments. There isn't yet a "big picture"
documentation, but if you don't understand something I gladly expalin
it, and use the opportunity to document it at the same moment.

On Oct 9, 7:30 am, param <singh.prab...@gmail.co> wrote:
> Hi Alex,
>
> Good work ..
> I am also interested in doing suck kind of think.If you want any help
> let me know
>
> thanks
>
> On Oct 9, 3:50 am, Axel Kittenberger <axe...@gmail.com> wrote:
>
> > While there is possible JSNI browser interface to determine a
> > selection, AFAIK the browser generally don't provide an interface to
> > get much of the cursor information. Firfox maybe has some XUL commands
> > for this, but thats it. Nevertheless I will seize the opportunity plug

> > my project AceArea --http://code.google.com/p/acearea/--it's an


> > editor completly* writen in GWT, that does not use the browser
> > internal editor like almost all the editors including RichTextArea do,
> > but implements it all in javascript, this gives the coder absolute
> > control. However while it has gone a far way, and even is already
> > useable enough for me to use it myself, I cannot recommend it yet in a
> > production environment nor are RichText elements like bold, italics,
> > yet implemented....
>
> > *99% GWT, 1% JSNI
>
> > On Oct 8, 10:57 pm, s4nTuZz0 <squattr...@gmail.com> wrote:
>
> > > Hi, i'm interested to your same questions. i've spent a lot of time
> > > above, unsuccesfully. anyone can give us any help ? :-) thanks.
>
> > > On Oct 8, 2:49 pm, "efreetm...@gmail.com" <efreetm...@gmail.com>
> > > wrote:
>
> > > > Hey,
>
> > > > I need to read cursor position and selection length in RichTextArea.

> > > > Any suggestions how to do this?d

efree...@gmail.com

unread,
Oct 9, 2007, 9:59:02 AM10/9/07
to Google Web Toolkit
> I only dont
> undestart why on getSelectionStartNode you start counting nodes, and
> not retrieve the node as Element right away.

Because:
1) I have very limited knowledge on javascript.
2) I need to know the selection start relating to the document and not
the node (startContainer).

I would be very happy if you could show me simpler way of doing this..

Peter Blazejewicz

unread,
Oct 9, 2007, 7:31:00 PM10/9/07
to Google Web Toolkit
hi Axel,

On Oct 9, 3:30 pm, Axel Kittenberger <axe...@gmail.com> wrote:
> Things on the general TOWISH list are:

> .............


> * Safari support, I I have not right now easy access to a safari
> browser, and well other reasons see opera.

you're probably on Windows machine so you can use Safari 3.0 beta for
Windows and WebKit nightly builds:
http://nightly.webkit.org/
I'm using it for testing on Windows machine when I'm off of my mac
(WebKit has really decent inspector tool you could find useful to gif
your html layout and other things at runtime),

regards,
Peter

Axel Kittenberger

unread,
Oct 10, 2007, 4:43:28 AM10/10/07
to Google Web Toolkit
Thanks will try it out. Altough my favorited development environment
is linux, the last time I tried out some Safari clone for windows, it
was pretty unusable.
After all at my university they have 1 computer lab with Macs I just
have to _go_ there and try out if AceArea works, respectavely what
doesn't work. It's on the TODO list ;-)

On Oct 10, 1:31 am, Peter Blazejewicz <peter.blazejew...@gmail.com>
wrote:

Reply all
Reply to author
Forward
0 new messages