Copy link to clipboard
Copied
Hi.
I know, it is a basic thing. Theoretical I now the answer, but it doesn´t work.
I want to delete double line-breakes. Ishould work with the siple script:
app.findGrepPreferences.findWhat = "\\r\\r"; //or \\r{2,}
app.changeGrepPreferences.changeTo = "\\r";
app.selection.paragraphs.everyItem().changeGrep();
If I search for them one by one, the´ll be found. Not as a double-pack!
???
By definition a search on paragraphs won't find 2 \r as a paragraph is defined as until and including one \r (or end of story).
If you don't wont to search the entire story do.
app.selection[0].changeGrep();
or app.selection[0].texts[0].changeGrep();
Don't forget the [0] by the selection
HTH
Trevor
Copy link to clipboard
Copied
Line 3 is wrong. Try this:
app.selection[0].parentStory.changeGrep();
Peter
Copy link to clipboard
Copied
Ok Peter you are right. But I do not have this bug in my original code. I have made it shorter for this thread. It works, but just by searching for one line-breake. If I search for two of them nothing happens, not even an error-alert
Copy link to clipboard
Copied
By definition a search on paragraphs won't find 2 \r as a paragraph is defined as until and including one \r (or end of story).
If you don't wont to search the entire story do.
app.selection[0].changeGrep();
or app.selection[0].texts[0].changeGrep();
Don't forget the [0] by the selection
HTH
Trevor
Copy link to clipboard
Copied
That´s it!
Now I can see it clearly, of course.
Thank you (all) for the hint.
Copy link to clipboard
Copied
Hi Trevorׅ,
I think it is ok when the following style is same as the previous. If not it overrides the following para style. Is there anyway to retain them as is??
Copy link to clipboard
Copied
app.findGrepPreferences.findWhat = "\\r+\\r"; //or \\r{2,}
app.changeGrepPreferences.changeTo = "\\r";
app.selection[0].changeGrep();
Seems to work for me
Copy link to clipboard
Copied
Something in your original code may interfere with what you're trying to do and lead to the behaviour that you see. But your 3-line snippet behaves as it should. The line
app.selection[0].paragraphs.everyItem().changeGrep()
looks for two or more \r in each paragraph, and a paragraph cannot contain more than one \r. That's why looking for \r wors and looking for \r\r does not. To find multiple \r have to target the story, not individual paragraphs.
P.
(Trevor beat me to it)
Copy link to clipboard
Copied
🙂