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

Filtering lines with a selection
https://www.nisus.com/forum/viewtopic.php?f=17&t=3734
Page 1 of 1

Author:  js [ 2010-05-06 13:01:44 ]
Post subject:  Filtering lines with a selection

Is there a simple means to filter all lines of a text that have a selection, copying those lines into a new document?

Author:  Kino [ 2010-05-07 05:49:49 ]
Post subject:  Re: Filtering lines with a selection

It is not clear to me what you mean by “filter” and by “lines”. Anyway...
Code:
 $doc = Document.active
$sels = $doc.textSelections
$lines = Array.new

foreach $sel in $sels
   $a = $sel.text.rangeOfLineAtIndex $sel.location
   $sel.location = $a.location
   $b = $sel.text.rangeOfLineAtIndex $sel.bound
   $sel.bound = $b.bound
   if $lines.lastValue != $sel.subtext
      $lines.appendValue $sel.subtext
   end
end

$LF = Cast to String "\n"
$lines = $lines.join $LF
Document.newWithText $lines

If you mean “paragraphs” by “lines”, replace rangeOfLineAtIndex with rangeOfParagraphAtIndex.

Author:  js [ 2010-05-07 10:41:36 ]
Post subject:  Re: Filtering lines with a selection

This is a great and extremely useful macro, thank you.
I wanted the paragraphs rather than lines and made the necessary changes. There is a little problem though I don't quite understand: I don't need/want the empty lines between the citations. I thought I could just delete the two lines of your macro which have "$LF" in them. But I d not get the desired result. Why is that?

Author:  Kino [ 2010-05-07 18:13:19 ]
Post subject:  Re: Filtering lines with a selection

js wrote:
I don't need/want the empty lines between the citations. I thought I could just delete the two lines of your macro which have "$LF" in them. But I d not get the desired result.
Use $lines = $lines.join '' instead of the two lines.

Quote:
Why is that?
See the explanation of join command in the Macro Reference.

Author:  js [ 2010-05-07 22:35:12 ]
Post subject:  Re: Filtering lines with a selection

Thank you. Everything fine now.

Author:  js [ 2010-09-15 10:18:26 ]
Post subject:  Re: Filtering lines with a selection

While using Kinos macro to delete all lines that have a selection, I sometimes found that individual paragraphs were not deleted. In the end I found the origin of the problem: I had sometimes done selections by dragging over several paragraphs at once in order to have them deleted. Of course this selects also the returns between the paragraphs. In this case the macro does not delete the first line. I wonder if this can be remedied?

Author:  Kino [ 2010-09-15 18:21:32 ]
Post subject:  Re: Filtering lines with a selection

js wrote:
While using Kinos macro to delete all lines that have a selection, [ . . . ]
You seem to have confused this thread with another one to which I have posted a revised version of the macro.

As to the macro posted to this thread, it can be simplified as follows.
Code:
Menu ':Edit:Select:Select Paragraph'
# or Send Selector 'selectParagraph:'
Menu ':Nisus Writer Pro:Services:New Nisus Document With Selection'
In Snow Leopard, the last command does not work unless it is enabled in the Keyboard System Pref.

Author:  js [ 2010-09-16 03:08:27 ]
Post subject:  Re: Filtering lines with a selection

I fear this is what I did. Glad to learn about both ways to remedy the problem. Thank you.

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