Reply to topic  [ 4 posts ] 
Select contents of Table Cell 
Author Message

Joined: 2006-03-12 12:32:47
Posts: 138
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!


2007-12-27 19:47:40
Profile
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
Post 
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


2008-01-02 18:20:21
Profile WWW

Joined: 2006-03-12 12:32:47
Posts: 138
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.


2008-01-02 23:14:37
Profile
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
Post 
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


2008-01-03 01:54:25
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software