Skip to main content
dublove
Legend
August 8, 2025
Answered

How can we determine the different operation targets of sel[j] based on the cursor state?

  • August 8, 2025
  • 1 reply
  • 750 views

I am not very clear about the current selection object and its hierarchical relationships, especially the representation of the parent level. Could someone clarify these relationships?


For example:
Situation 1: When the cursor is outside the table
    A. When the cursor is in a paragraph with no selection, sel[j] is the entire paragraph.
    B. If part of the text is selected, sel[j] is the selected text. (This includes selecting all text within the text box.)
    C. If the text box is selected, sel[j] is all content within the text box (including images, text, and tables).

 

Situation 2: When the cursor is inside a table
   D. If the cursor is within a cell, sel[j] is the current cell.
   E. If multiple cells are selected via drag, sel[j] is the selected cells.
   F. If the entire table is selected, sel[j] is the entire table.

 

Thank you very much.

Correct answer Manan Joshi

 

If I drag and select several cells, how do I get the text content?

If I select text and tables outside the table, how do I get the text in the cells?

Sunil Yadav wrote this before, and it is also invincible.

I don't know why there are two text[0].text[0]

Occasionally, it may fail.

obj.texts[0].tables.everyItem().cells.everyItem().texts[0].texts[0].appliedParagraphStyle = "myTabBodyPar";

 

If I select the entire text Frame, how can I retrieve the text in the cell?

 

 


If you have multiple cells selected the following will give you text of the cells

app.selection[0].cells.everyItem().contents

If you have some text selected which is outside the table and have the table selected as well. then the following will get you contents of all the cells in the selected table

app.selection[0].tables.everyItem().cells.everyItem().contents

If the extire frame is selected then the following would work

app.selection[0].tables.everyItem().cells.everyItem().contents

-Manan

1 reply

Community Expert
August 9, 2025

When the cursor is in a text within or outside the table without any selection then it is insertionPoint. What you can do is make different selections with whatever use case you want and then run the following code

alert(app.selection[0].constructor.name)

-Manan

-Manan
dublove
dubloveAuthor
Legend
August 9, 2025

For example, how do you indicate the entire paragraph where the cursor is located?

Community Expert
August 9, 2025
app.selection[0].paragraphs[0].contents

Should give you the paragraph where the current cursor is placed

-Manan

-Manan