Move table rows

Get help using and writing Nisus Writer Pro macros.
Post Reply
johseb
Posts: 47
Joined: 2016-02-13 10:01:29

Move table rows

Post by johseb »

I downloaded a couple of macros to move table rows up/down (written by @phspaelti and shared in the thread https://nisus.com/forum/viewtopic.php?f ... own#p30721).

The "Move down" macro works perfectly but the "Move up" macro doesn't.
I had a look to the macros but the issue is not apparent to me; it could be a problem with the macro itself or with my system.

Philip, any chance you can have a look to the macros? :wink:

Thanks
Attachments
Move Table Rows Up.nwm
(7.08 KiB) Downloaded 638 times
Move Table Rows Down.nwm
(7.22 KiB) Downloaded 647 times
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Move table rows

Post by martin »

This failure is not Philip's fault. It looks like the issue is due to the way Nisus Writer incorrectly interprets the selection created by the macro:

Code: Select all

$insertPoint = TextSelection.new $cell.text, Range.new(0,0)
That generated selection should always be a text insertion point, no matter what. However, if the targeted table cell is empty the text selection is promoted to a full cell selection– a table selection. That distinction doesn't normally matter, but with such a selection in place the macro's paste operation inserts the row(s) at the wrong location, one row too far down, and thus there's no change in content.

There's a few ways we might work around this problem. The macro could instead generate a selection that's one row earlier, like so:

Code: Select all

If $insertRow.location > 0
	$selectRowRange = Range.new $insertRow.location - 1, 1
	$insertPoint = TableSelection.new $sel.table, $selectRowRange
End
But as the "If" statement's location check may reveal, this only works when you don't need to move rows to the very top of the table.

A complete workaround could instead insert a placeholder character into the empty cell, so the proper text selection is always generated by the macro. Once the macro finishes moving the table rows, the temporary placeholder can be excised. I'll attach an amended macro that uses this strategy. I'll also file a bug report that we should fix this macro selection behavior.

Thanks!
Attachments
Move Table Rows Up.nwm.zip
(2.99 KiB) Downloaded 650 times
johseb
Posts: 47
Joined: 2016-02-13 10:01:29

Re: Move table rows

Post by johseb »

Thank you Martin, the macro now works like a charm (and thanks to Philip for writing the two original macros).
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Move table rows

Post by phspaelti »

Thank you, Martin.
I'm glad you were able to fix that. The problem and its solution would not have been obvious to me.
philip
Post Reply