Sunday, August 19, 2007


Tables and keystrokes

The question was asked in the U2U forum this week: how to use the keyboard to move the insertion point out of a table to the story containing it.

The answer is to navigate to the start of the text in the top-left cell and then hit Left Arrow on the keyboard. The quick way to navigate there from anywhere in a table is:

Command-Option-A (or Ctrl-Alt-A)
Left Arrow

If the top-left cell is empty, hitting the Left Arrow key is unnecessary. So, depending on the state of the top-left cell, to get out of the table takes three or four keystrokes. None of which has much to do with scripting. But that raised the question, how do you use the keyboard to get into a table?

And that requires a script (to which you could attache a shortcut). I composed this script to get the cursor into the first cell of the next table in the current text flow -- bear in mind that a table could be inside the text in a cell in another table:
//DESCRIPTION: Move cursor to next table
if (app.documents.length > 0 && app.selection.length > 0) {

function jumpToNextTable(sel) {
  if (sel.hasOwnProperty("baseline")) {
    try {[0].insertionPoints[0]);
    } catch(e) {};

  function findTable(sel) {
    var story = sel.parent;
    if (sel.index < story.length - 1) {
      var tables = story.characters.itemByRange(sel.index, story.length - 1).texts[0].tables;
      if (tables.length > 0) return tables[0];

hello dave, one interesting question remains unanswered: how to get out of the table by script?. e.g. how to select paragraph preceding the table in which the selection currently resides. (maybe it is somehow obvious or trivial, but I can not find the right way)
Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?