• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Isn't a text selection not an object?

Community Expert ,
May 04, 2022 May 04, 2022

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.

Views

70

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , May 04, 2022 May 04, 2022

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
...

Votes

Translate

Translate
Community Expert ,
May 04, 2022 May 04, 2022

Copy link to clipboard

Copied

LATEST

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"));

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines