nisus.com
https://www.nisus.com/forum/

Select contents of Table Cell
https://www.nisus.com/forum/viewtopic.php?f=17&t=2722
Page 1 of 1

Author:  Bob Stern [ 2007-12-27 19:47:40 ]
Post subject:  Select contents of Table Cell

The result of the macro commands "Select Table Cell n, m" and "Select Relative Table Cell n, m" is the cell contents preceded and followed by a Return.

How can I avoid these return characters being included?

Alternatively, what macro steps or Perl block will strip the leading and trailing returns? I don't see any macro commands to do string manipulation. (I'm a Perl neophyte, so please don't assume any knowledge in your response.)

Thanks!

Author:  martin [ 2008-01-02 18:20:21 ]
Post subject: 

Yes, those commands will select all of the cell's content, whatever it may be. Once a selection has been made (eg: via the Select Table Cell command), here's some code to have the selection exclude newlines:

Code:
$limitedLoc = Selection Location
$limitedLen = Selection Length

# strip newlines from the start
If Find '^\n+', 'Es'
    $newlineCount = Selection Length
    $limitedLoc += $newlineCount
    $limitedLen -= $newlineCount
End

# strip newlines from the end
Set Selection $limitedLoc, $limitedLen
If Find '\n+$', 'Es'
    $newlineCount = Selection Length
    $limitedLen -= $newlineCount
End

Set Selection $limitedLoc, $limitedLen

Author:  Bob Stern [ 2008-01-02 23:14:37 ]
Post subject:  Bug in "Copy Table Text" & "Copy Text Onl

Thanks, Martin!

I now see that my problem is caused by inconsistencies among the results of three Copy commands if used after an entire table cell is selected. The inconsistency occurs irrespective of whether the commands are invoked manually or in a macro.

Specifically, suppose a table cell includes one or more words without any newline characters.

Suppose I position the cursor in that cell and then select the entire contents of the cell using either the menu command "Table:Select:Cells" or the macro equivalent "Select Relative Table Cell 0, 0".

If I perform Edit:Copy:Copy (command-C) and then paste the clipboard into an empty document window, I get the contents of the table cell as expected.

However, if I perform Edit:Copy:Copy Text Only,
I get the contents of the table cell preceded by a spurious return and followed by another spurious return.

If I perform Table:Copy Table Text,
I get the contents of the table cell followed by a spurious return.

It appears to me that the returns inserted by "Copy Text Only" and "Copy Table Text" represent bugs.

Author:  martin [ 2008-01-03 01:54:25 ]
Post subject: 

The additional newlines are indeed a bug- I'll file a report. The reason they appear is because copying the table cells as text can insert newlines before/after each table row.

If you're always working with exactly one table cell, this code should do what you want by bypassing the smart text conversion:

Code:
$text = Read Selection
$text = Cast to String $text, false
Write Clipboard $text

Page 1 of 1 All times are UTC - 8 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/