cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X

getTextSelection() not returning the selected range

samah
1-Newbie

getTextSelection() not returning the selected range

Hello Adepters,


We have an empty element "endReusableBlock" that only has one attribute "id". It is styled as a block, with its text hidden and we add some gentext after it.


[cid:image002.png@01CCFB81.BB0260F0]


If we select a block that ends with the hidden element:

[cid:image003.png@01CCFB81.BB0260F0]

And use Application.ActiveDocument.getTextSelection() to get the selected text, the function doesn't return the hidden element in the range. If I change the styling of the element and make it non hidden. The function "getTextSelection()" returns is in the range.

Does anybody have an idea how to solve this?

Thanks,

-Samah
4 REPLIES 4

Hi Samah--



You should be able to control display of hidden objects using code, so
you could do something like this:



// return selection including hidden objects

// NB: code not tested, debugging is left as an exercise

var doc = Application.activeDocument;

var hidden = doc.getOption("hidesuppressed");

doc.setOption("hidesuppressed","off");

var content = doc.getTextSelection;

doc.setOption("hidesuppressed","on");



...



This is javascript code, you'll need to tweak as necessary (mainly
variable typing) if you're using Java.



--Clay





Clay Helberg

Senior Consultant

TerraXML


samah
1-Newbie
(To:samah)

Hi Clay,

Thanks for your help. This solved the problem.

-Samah

Hi Samah--



I'm glad it worked for you. However, I just realized I did make one
mistake there: in the last line, the hidesuppressed option should be set
back to the value we stored previously in the variable "hidden", instead
of just setting it to "on". So the last line should look like this:



doc.setOption("hidesuppressed", hidden);



That way, if a user has turned that option off via the Preferences
panel, you won't end up turning it back on for them without their
knowing it. It simply will simply restore the setting to its previous
state.



--Clay



Clay Helberg

Senior Consultant

TerraXML


samah
1-Newbie
(To:samah)

Hi Clay,

Makes sense. Thanks.

-Samah
Announcements

Top Tags