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

Community Tip - You can change your system assigned username to something more personal in your community settings. X

Selection issue using ACL commands

pzorrilla
1-Visitor

Selection issue using ACL commands

Hello Experts!!


8 REPLIES 8

It's probably going to be a multi-step process. You'll need to get the oid and pos from the start and end, then use goto_oid(oid, pos) to move the caret to those locations and use oid_caret to get the parent oid. You can then re-select the selection based on those points using the mark command. That might work. I've found the selection code very difficult and buggy in recent releases, especially since the support for xinclude. Behavior is different based on if you are using xinclude vs file entities and can also be different if you have gentext on or off. Things that seem to work for your selection code can sometimes cause serious bugs in seemingly unrelated parts of your code (I just spent 3 months going back and forth in production with a cascade of errors in this very area of code trying selectively update ids on a selection for copy/cut/paste), so test more than you think necessary and get users to bang on it before you deploy to a larger audience if possible.

Ditto what Steve says Paulette.


The get_selection_oids() function below can return selected oids if you know the parent and target search tag names (or target regex of oid_find_children()).



function ancestor_oid(o, tag, highest=0, doc=current_doc()) {


local saveo;


while (oid_name(o)!=tag) {
if (o == oid_first_tag(doc)) {
# no such animal
return 0;
}
o = oid_parent(o);
}

if (highest) {
saveo=o;
while (o!=oid_first_tag(doc)) {
if (oid_name(o)==tag) {
saveo=o;
}
o=oid_parent(o);
}
o=saveo;
}
return o;
}


function get_selection_oids(par,chld_tag,rgx=0) {
# returns colon delimited list of found chld_tag oids in selection, excluding atict:del deletions


local o1, o2, p1, p2, arr[], selarr, i;

o1=selection_start(p1)
o2=selection_end(p2)
if (!oid_find_children(par,arr,chld_tag,rgx)) { return 0; }
for (i=1;i<=high_bound(arr);i++) {
if (ancestor_oid(arr[i], 'atict:del')) { continue; }
if (oid_offset(o1,p1,arr[i],-1)>=0&&oid_offset(o2,p2,arr[i],0)<=0) {
selarr.=":$arr[$i]"
}
}
sub('^:','',selarr)
return selarr
}

Oops, make that "... if you know theparent oid and target search tag name ..."

BrianJ
12-Amethyst
(To:pzorrilla)

Hi Paulette,

I may be misunderstanding what you're trying to do and what you've done
so far, but here's some comments based on what you said.

In ACL world, selection start and end points (and anchor points, which
may not be the same as the start or end points) are defined by the oid
of the parent they are children of, and an offset from the start of that
parent. The problem is that the offset includes both start and end tags,
and who knows what else. You can't call oid_child(startOid, startOffset)
and have it reliably give you the oid of the start of a selection. So
ACL works fine if you're just trying to save the points of a selection
to later restore it (assuming you aren't changing stuff inside the
selection), but if you want to do something with the contents of the
selection using oid-based functions, it becomes a lot harder (to me, at
least).

Have you looked at the selected_element ACL function? It sounds like it
will do what you want, as long as the selection is only a single element.

If you're dealing with multiple selected elements, and want to get those
to operate on them, I've found it easier to do in java. Here's code to
get a list of the selected nodes. You'll need to pass it the selection
as a range argument, which you can get by calling getTextSelection() on
an ADocument object:

public static List<node> getRangeContents(Range range) {
List<node> rangeNodes = new ArrayList<node>();
Node startContainer = range.getStartContainer();
int startOffset = range.getStartOffset();
Node endContainer = range.getEndContainer();
int endOffset = range.getEndOffset();
NodeList startKids = startContainer.getChildNodes();
Node node = startKids.item(startOffset);
NodeList endKids = endContainer.getChildNodes();
Node endNode = endKids.item(endOffset - 1);
while (node != null) {
rangeNodes.add(node);
if (endNode == null || node.isSameNode(endNode)) {
break;
}

node = node.getNextSibling();
}

return rangeNodes;
}

Take note that this will return ALL nodes in the selection, which may
include xml comments, processing instructions, etc.

Hope that helps!
Brian

Hello Brian J. and everybody.



I'm sorry to respond until now. I think my best solution will be to get the content selected from the Arbortext Editor using some of the acl commands and then manage that information in Java. I tested a little with the "selection_markup()" command and I could see that I'm receiving a String representation of the selection, I wasn't sure about doing that since the content will be modified, this means I'll add some extra elements and maybe I'll remove some others, also because I'm doubting about what's the largest text I could pass as a String to my Java object, my best idea for the moment is to remove the selected content and insert the modified content which will correspond to my modified String in Java, I am not sure about how to identify the exact position of the extraction in the document, the whole process is quite complicated because I don't want to insert the modified content in a different position; I haven't had time to test all the code you kindly provide me, but as soon as I have a chance to test it I'll let you know what's the best solution, at least for me 😄



Again thank you so much for your ideas, suggestions and time. I really appreciate a lot your support.



Paulette.

Hello everyone!


At the end I dediced to use the selection_markup() ACL command, once I have the corresponding String with my selection, I pass it as a parameter to my Java Object and I make all changes in Java according to what I need, finally I'll get the new String with its corresponding changes and I'll insert it using the delete_mark and insert("modified_string") ACL commands; now, what I would like to add is a new "fancy" feature, once I put back the new content into the book I would like to select this new "modified" content. All the previously selected section is continuous and I was thinking that maybe using marking I could mark the begin and the end of my selection; however I don't know quite well how to manage marking with ACL, I'm not sure neither if I could have a way to identify my previously selected chunk of sections.


Does anybody of you knows a way to achieve my objective? I mean, is there any command which could help me to select again a previously selected, modified, removed and re-inserted chunk of sections?


I hope anybody could give me a clue or any information of managing selections in Arbortext using ACL; as always I appreciate a lot your time and responses.



Paulette

Also look at the "insert_string" command also which has some options you might find useful such as -sgml (w/markup)



local o1, p1, o2, p2;


o2=selection_end(p2);


goto_oid(o1,p1);
goto_oid(o2,p2);
re-selects it. After inserting a new string/markup insert you probably have a different end so you'd want to save a new selection end (cursor position after insert) with


o3=selection_end(p3);


goto_oid(o1,p1);
goto_oid(o3,p3);
Where this breaks down unfortunately is when the selection was made backwards (right to left); use oid_offset to test for that.



This function returns the character offset between the two document locations specified by oid1,pos1 and oid2,pos2 respectively. Each non-text object (that is, markup, equations, graphics) counts as one character. The offset returned will be negative if the location specified by oid2,pos2 comes before the position specified by oid1,pos1."




In Reply to Paulette Zorrilla:



Hello everyone!


At the end I dediced to use the selection_markup() ACL command, once I have the corresponding String with my selection, I pass it as a parameter to my Java Object and I make all changes in Java according to what I need, finally I'll get the new String with its corresponding changes and I'll insert it using the delete_mark and insert("modified_string") ACL commands; now, what I would like to add is a new "fancy" feature, once I put back the new content into the book I would like to select this new "modified" content. All the previously selected section is continuous and I was thinking that maybe using marking I could mark the begin and the end of my selection; however I don't know quite well how to manage marking with ACL, I'm not sure neither if I could have a way to identify my previously selected chunk of sections.


Does anybody of you knows a way to achieve my objective? I mean, is there any command which could help me to select again a previously selected, modified, removed and re-inserted chunk of sections?


I hope anybody could give me a clue or any information of managing selections in Arbortext using ACL; as always I appreciate a lot your time and responses.



Paulette


Lou!


Tahnk you so much for your response, I have been working those days testing with different commands, however I think I was using them in a wrong way, I didn't know that using only mark command Arbortext would select the content, I was using the oid_select() command but at the end I wasn't receiving the complete selection.


I tested the commands you sent me and at the end I need to use the o3, p3 option after I insert the new content, this way my plugin is getting the correct bunch of sections, in my case, which I selected, modified, removed and re-inserted. I tested also with selections from right to left and it seems don't have any problem. I'll continue testing with other documents and other selections, but for the moment my code is working only with mark and goto_oid acl commands.



Again, thank you so much and I'll let my code in case anybody could find it useful.



local $markup = java_instance($obj,"navigateThroughSelection", $selection, $main::EPIC_CODE_HOME); #Modify the wrapped content, returns $markup which corresponds to selected and modified content.


java_delete($obj); #Delete Java Object



if($markup != "-1") {


insert(markup);


goto_oid(o1,p1);


mark begin;


goto_oid(o3,p3);


mark end;


Announcements

Top Tags