Copy link to clipboard
Copied
Dear all,
I tried to check for an existing text selection:
var oDoc = app.ActiveDoc;
var oTSel = oDoc.TextSelection;
if (oTSel.ObjectValid()) {
$.writeln ("we got it");
}
But this creates an error during parsing.
I need to dive deeper into the object:
var oDoc = app.ActiveDoc;
var oTSel = oDoc.TextSelection;
if (oTSel.beg.obj.ObjectValid()) {
$.writeln ("we got it");
}
This works - but I do not understand, why the text selection itself - which is indicated to be an object - does not allow a direct check.
The TextSelection property is actually a TextRange object consisting of two TextLoc objects, one at the beginning of the TextRange and one at the end. So your second code block is actually doing this:
var oTSel = oDoc.TextSelection;
var textLoc = oTSel.beg;
if (textLoc.obj.ObjectValid () === 1) {
$.writeln ("we got it");
}
Apparently, ObjectValid () is not a method on a TextRange object. One way you can check this is to run this:
var oTSel = oDoc.TextSelection;
// oTSel is a TextRange object
...
Copy link to clipboard
Copied
The TextSelection property is actually a TextRange object consisting of two TextLoc objects, one at the beginning of the TextRange and one at the end. So your second code block is actually doing this:
var oTSel = oDoc.TextSelection;
var textLoc = oTSel.beg;
if (textLoc.obj.ObjectValid () === 1) {
$.writeln ("we got it");
}
Apparently, ObjectValid () is not a method on a TextRange object. One way you can check this is to run this:
var oTSel = oDoc.TextSelection;
// oTSel is a TextRange object. See what methods it has.
alert (oTSel.reflect.methods.sort ().join ("\r"));