...

View Full Version : How to move start and end points of a range?



Krupski
07-01-2011, 04:36 PM
Hi all,

I am trying to wrap a text selection with BBCode. I have it working, but there is one final part I need help with.

First, here's the code I'm using:


var range = ed.selection.getRng(true);
var s = ed.dom.create('span', {}, '');
range.surroundContents(s);
s.innerHTML = open + s.innerHTML + close;
ed.selection.select(s);
This is an explanation of each line:


get the user's selection as a W3C compatible range
create an empty <span> element
surround the selection range with the span
convert the selection from "selection" to "selection" by using innerHTML
select the new <span> element


Of course, selecting the span ALSO selects the BBCode open and close tag... like in this picture:

http://three-dog.homelinux.com/images/selection_move.jpg

So, the last thing I need to do (the whole point of this post)... how do I MOVE the range start and end points so that only the selection is selected and NOT the whole thing?

I will greatly appreciate if someone can tell me how to move those selection start and end points...

Thanks!

-- Roger

Krupski
07-04-2011, 09:59 PM
Really? Nobody? :(

low tech
07-05-2011, 01:48 AM
Hi Krupski

I sent you a pm.

LT

tfburges
07-05-2011, 05:18 AM
I don't have any experience with this, but have you seen this mini-tutorial? I know it's not what you're trying to do but it might offer some insight or give you an idea that you haven't thought of yet.

http://the-stickman.com/web-development/javascript/finding-selection-cursor-position-in-a-textarea-in-internet-explorer/

Hopefully that helps if you haven't seen it yet.

Krupski
07-05-2011, 04:49 PM
Hi Krupski

I sent you a pm.

LT
Got it thanks! :thumbsup:

Krupski
07-05-2011, 04:50 PM
I don't have any experience with this, but have you seen this mini-tutorial? I know it's not what you're trying to do but it might offer some insight or give you an idea that you haven't thought of yet.

http://the-stickman.com/web-development/javascript/finding-selection-cursor-position-in-a-textarea-in-internet-explorer/

Hopefully that helps if you haven't seen it yet.

Not exactly what I was looking for BUT all the comments in that code help explain a lot... which may just give me enough to figure it all out. Thanks! :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum