Skip to main content
Participant
July 31, 2007
Question

Get the real actual selection in code view. DOM getselection

  • July 31, 2007
  • 2 replies
  • 281 views
Dreamweaver automatically gives you the whole node if you have part of the inside of a tag selected. I want exactly what I have highlighted in the code view not a node.

Correct would be:

="anid">some text</d

Not expanded to something like this:

<div class="anid">some text</div>

The second is what dreaweaver defaults to, but I want to count the exact number of characters highlighted in code view or the number of characters in the entire document. In fact I'd like to not use the DOM at all. Is there a way to just get a raw array of all the selection without auto-expanding to the nearest node.

I'm using this code:

var theDOM = dw.getDocumentDOM();
var theWholeDoc = theDOM.documentElement.outerHTML;

var theSel = dreamweaver.getSelection(); // Extract the selection
var selText = theWholeDoc.substring(theSel[0],theSel[1]);
alert(selText);

Any help is much appreciated, this is very frustrating. In other words I don't just want to get the selection by whole nodes, I want to get the selection even if it starts halfway through one tag and ends halfway into another.

Thanks!!!
Nick
This topic has been closed for replies.

2 replies

Participant
July 31, 2007
Wow great Tom Muck, that worked well.

I think dreamweaver should add the source property to the extension help section under: Objects, properties, and methods of the Dreamweaver DOM

Thanks again.
Nick Juntilla
Inspiring
July 31, 2007
Try this:

var dom = dw.getDocumentDOM();
var theSel = dom.source.getSelection();
var startPoint = theSel[0];
var endPoint = theSel[1];
alert(dom.source.getText(startPoint,endPoint));

It's a bit wordy for clarity, but that should get you what you want.


--
Tom Muck, Adobe Community Expert
Dreamweaver Extensions/Articles -- http://www.tom-muck.com/
Cartweaver Development Team - http://www.cartweaver.com/
Extending Knowledge Daily - http://www.communitymx.com/


"nicksapoet" <webforumsuser@macromedia.com> wrote in message
news:f8o76q$bfl$1@forums.macromedia.com...
> Dreamweaver automatically gives you the whole node if you have part of the
> inside of a tag selected. I want exactly what I have highlighted in the
> code
> view not a node.
>
> Correct would be:
>
> ="anid">some text</d
>
> Not expanded to something like this:
>
> <div class="anid">some text</div>
>
> The second is what dreaweaver defaults to, but I want to count the exact
> number of characters highlighted in code view or the number of characters
> in
> the entire document. In fact I'd like to not use the DOM at all. Is
> there a
> way to just get a raw array of all the selection without auto-expanding to
> the
> nearest node.
>
> I'm using this code:
>
> var theDOM = dw.getDocumentDOM();
> var theWholeDoc = theDOM.documentElement.outerHTML;
>
> var theSel = dreamweaver.getSelection(); // Extract the selection
> var selText = theWholeDoc.substring(theSel[0],theSel[1]);
> alert(selText);
>
> Any help is much appreciated, this is very frustrating. In other words I
> don't just want to get the selection by whole nodes, I want to get the
> selection even if it starts halfway through one tag and ends halfway into
> another.
>
> Thanks!!!
> Nick
>
>