Pages: 1
Print
Author Topic: MoveToElement() skips thead and rows  (Read 1878 times)
KdG
Member

Posts: 19


WWW
« on: March 04, 2014, 04:38:27 AM »

XMetaL Author 6.0

I have documents with cals-tables in them.
If I run a macro with a simple loop with a rng.MoveToElement() to fill all open id'd the loop skips all <thead> elements, most <entry> elements and the elements from about row 2 and beyond.
Is this a bug? What is wrong here? Is there a solution?


To reproduce, run the macro on the demo-table below:
   // XMetaL Script Language JSCRIPT:
   var rng=ActiveDocument.Range;
   rng.MoveToDocumentStart();
   var n=0;
   while (rng.MoveToElement()) {
      if (rng.hasAttribute("id") && rng.ContainerAttribute("id")=="") {
         n++
         rng.ContainerAttribute("id") = "P"+n;
   
      }
   }


<table>
   <tgroup cols="5">
      <colspec/><colspec/><colspec/><colspec/><colspec/>
      <thead>
         <row><entry><p>K</p></entry><entry><p>L</p></entry><entry><p>M</p></entry><entry><p>N</p></entry><entry><p>O</p></entry></row>
      </thead>
      <tbody>
         <row><entry><p>A</p></entry><entry><p>F</p></entry><entry><p>P</p></entry><entry><p>20</p></entry><entry><p>V</p></entry></row>
         <row><entry><p>B</p></entry><entry><p>G</p></entry><entry><p>Q</p></entry><entry><p>30</p></entry><entry><p>W</p></entry></row>
         <row><entry><p>C</p></entry><entry><p>H</p></entry><entry><p>R</p></entry><entry><p>40</p></entry><entry><p>X</p></entry></row>
      </tbody>
   </tgroup>
</table>
« Last Edit: March 05, 2014, 03:01:57 AM by KdG » Logged
XMetaLOldTimer
Administrator
Member

Posts: 57


« Reply #1 on: May 15, 2014, 03:15:12 PM »

You'll need to rewrite the code to use XMetaL's DOM APIs instead.

Range and Selection objects are limited to what elements they can select, especially if the requested selection state cannot be made by a user on-screen in Tags On or Normal view.  As you are seeing, it is not possible to select a thead programmatically and neither is it possible with a mouse.  When attempting to make such a selection, XMetaL will adjust the selection to the nearest location that is selectable on-screen and/or also permits text input like a entry element.

Regards,
Addam

Logged

Addam Smith, XMetaL Project Lead & Architect
JustSystems Canada Inc.
Pages: 1
Print
Jump to: