Filtering lines with a selection
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?
Re: Filtering lines with a selection
It is not clear to me what you mean by “filter” and by “lines”. Anyway...
If you mean “paragraphs” by “lines”, replace rangeOfLineAtIndex with rangeOfParagraphAtIndex.
Code: Select all
$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
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?
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?
Re: Filtering lines with a selection
Use $lines = $lines.join '' instead of the two lines.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.
See the explanation of join command in the Macro Reference.Why is that?
Re: Filtering lines with a selection
Thank you. Everything fine now.
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?
Re: Filtering lines with a selection
You seem to have confused this thread with another one to which I have posted a revised version of the macro.js wrote:While using Kinos macro to delete all lines that have a selection, [ . . . ]
As to the macro posted to this thread, it can be simplified as follows.
Code: Select all
Menu ':Edit:Select:Select Paragraph'
# or Send Selector 'selectParagraph:'
Menu ':Nisus Writer Pro:Services:New Nisus Document With Selection'
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.