Skip to main content
1-Visitor
March 6, 2012
Question

getTextSelection() not returning the selected range

  • March 6, 2012
  • 4 replies
  • 3499 views
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

    18-Opal
    March 6, 2012
    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


    samah1-VisitorAuthor
    1-Visitor
    March 7, 2012
    Hi Clay,

    Thanks for your help. This solved the problem.

    -Samah
    18-Opal
    March 7, 2012
    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


    samah1-VisitorAuthor
    1-Visitor
    March 7, 2012
    Hi Clay,

    Makes sense. Thanks.

    -Samah