Thank you Radu,
with your help, I have been able to put together the JSOperation (provided below) that does the following:
After selecting a range of cells in a table row, or an entire row:
- If any cell in the selection has attribute rotate = "...", the attribute "rotate" is removed for the entire row
- If none of the cells in the selection have the attribute "rotate", the attribute rotate = "1" is set for the entire selection
Now if selecting a range of cells across multiple rows (example here 4 cells = columns indexes 2 and 3, 2nd and 3rd rows), only the last row is affected by the JSOperation:
I assume this has to do with the fact that the selection correspond to 2 discontinued areas in the text view and that the getSelectionStart() and getSelectionEnd() return only the offset of the last xml fragment of the selection.
Maybe the function getSelectionIntervals() "Get the selection [start offset, end offset] intervals list" would do the trick but when I try to use it I got an error: "Could not find function getSelectionIntervals() ...". Do I need to update my Dita framework to make use of this function? How?
Code: Select all
function doOperation() {
if(authorAccess.getEditorAccess().hasSelection()) {
startOffset = authorAccess.getEditorAccess().getSelectionStart();
endOffset = authorAccess.getEditorAccess().getSelectionEnd();
results = authorAccess.getDocumentController().findNodesByXPath("../descendant-or-self::entry", true, true, true);
rotated = false;
for(i = 0; i < results.length; i++){
if(results[i].getEndOffset() > startOffset && results[i].getStartOffset() < endOffset && results[i].getAttribute("rotate") != null){
rotated = true;
}
}
if (rotated == true){
for(i = 0; i < results.length; i++){
if(results[i].getEndOffset() > startOffset && results[i].getStartOffset() < endOffset){
authorAccess.getDocumentController().removeAttribute("rotate", results[i]);
}
}
}
if (rotated == false){
for(i = 0; i < results.length; i++){
if(results[i].getEndOffset() > startOffset && results[i].getStartOffset() < endOffset){
authorAccess.getDocumentController().setAttribute("rotate", new Packages.ro.sync.ecss.extensions.api.node.AttrValue("1"), results[i]);
}
}
}
}
}