Page 1 of 1

macro to delete "tracks" containing certain characters

Posted: 2017-07-18 17:47:49
by Nobumi Iyanaga
Hello,

I am editing a file containing an enormous number of "track changes -- and I notice that NWP is very weak to deal with this kind of documents. If I open and edit it in MS Word, there are almost no problems, but in NWP, each change takes minutes and each time, the rainbow wheel is turning indefinitly... I really would like to request a better treatment of this kind of documents...

Anyway, this enormous number of "track changes" is the result of several "change all" for formatting. The editor who made these changes made "change all" to change all the spaces after "«" and before "»" into "non-breaking spaces". This is correct in terms of editing process, but leaving all these changes in "track changes" seems to me a rather silly thing...

Anyway, what I would love to have is a macro that would select every instance of "track change" which contains a "non-breaking space". Is such a macro possible?

Thank you very much in advance to whoever would be so kind as to write for me this macro...

Best regards,

Nobumi

Re: macro to delete "tracks" containing certain characters

Posted: 2017-07-19 17:14:14
by martin
Hi Nobumi,

Here's a macro that finds text in tracked changes. It will search all tracked deletions and replacements in your document, selecting those whose original (ie: deleted) text matches the search text. You can then either accept or reject them all.

As an aside, are you able to send us your document privately, so I can see the slowdown firsthand? I'd like to see if there's anything we can do to help Nisus Writer behave more smoothly. Thanks!

Re: macro to delete "tracks" containing certain characters

Posted: 2017-07-20 06:22:12
by Nobumi Iyanaga
Hello Martin,

Thank you for your reply and your excellent macro!

You wrote:
Here's a macro that finds text in tracked changes. It will search all tracked deletions and replacements in your document, selecting those whose original (ie: deleted) text matches the search text. You can then either accept or reject them all.
The macro worked very well. I could delete (that is, accept) more than 300 changes. -- But there are much more of the same kind, in which no traces of deleted text seem to be left; there are only the added elements which are indicated in the side bar...

It seems that NWP macro language lacks the "

Code: Select all

.addedTextContent"
property among the TrackedChange Object Properties. But going through the "

Code: Select all

.markedText"
or "

Code: Select all

.markedTextRange
"..., it seems possible to get the values of the added text?? The macro would be much more complicated, but is it possible to write such a macro, please...?

Thank you very much in advance!

You wrote also:
As an aside, are you able to send us your document privately, so I can see the slowdown firsthand? I'd like to see if there's anything we can do to help Nisus Writer behave more smoothly. Thanks!
Yes, surely. I will send you the file in a feedback. Thank you in advance for examining it, and see how it would be possible to improve NWP's behavior.

Best regard,

Nobumi Iyanaga

Re: macro to delete "tracks" containing certain characters

Posted: 2017-07-20 07:05:52
by martin
I'm very happy to help!
Nobumi Iyanaga wrote:The macro worked very well. I could delete (that is, accept) more than 300 changes. -- But there are much more of the same kind, in which no traces of deleted text seem to be left; there are only the added elements which are indicated in the side bar...
Ah yes, I should have anticipated this need. Here's an amended macro that can search tracked deletions and additions.
It seems that NWP macro language lacks the "

Code: Select all

.addedTextContent"
property among the TrackedChange Object Properties. But going through the "

Code: Select all

.markedText"
or "

Code: Select all

.markedTextRange
"..., it seems possible to get the values of the added text??
Yes, the trick is to set the selection to the marked text/range and then search only within the selection. You can see how it works in the updated macro.
Yes, surely. I will send you the file in a feedback.
Great, I'll be on the lookout for it, thank you!

Re: macro to delete "tracks" containing certain characters

Posted: 2017-07-20 22:57:39
by phspaelti
Nobumi Iyanaga wrote: It seems that NWP macro language lacks the "

Code: Select all

.addedTextContent"
property among the TrackedChange Object Properties. But going through the "

Code: Select all

.markedText"
or "

Code: Select all

.markedTextRange
"..., it seems possible to get the values of the added text?? The macro would be much more complicated, but is it possible to write such a macro, please...?
You should be able to use

Code: Select all

$addedText = $change.markedText.subtextInRange($change.markedTextRange)
But of course if you do a find on this subtext (or substring) the returned range values will not be applicable to the main text. That is why Martin does the find via the GUI.
The range value for the main text would have to be calculated with something like this:

Code: Select all

$isMatch = $addedText.find($findText, $findOps)
if $isMatch
    $findRange = Range.new $change.markedTextRange.location + $isMatch.location, $isMatch.length
end
NB: I have not tested any of this.

Re: macro to delete "tracks" containing certain characters

Posted: 2017-07-23 06:21:12
by Nobumi Iyanaga
Hello Martin,
Hello Philip,

Thank you for your new macro, Martin. I downloaded it and used it. It works perfectly, as I have expected. This helped much, and now, with much less "track changes", I can edit my document without difficulties. Thank you very much again!

As Philip points out, you use "GUI Find" to test if a track changed text contains an added item that matches those items to be found -- and this seems to slow down the macro...? But this is not a major problem; anyway, with your macro, I could make the file "workable".

Philip's codes seem very interesting, but I don't understand how they should be inserted in Martin's macro.

Anyway, I find that it is rather not very intelligent to record these kinds of "Replace All" in track changes (for example Replace All every space with a non-breaking-space for cases like "« " or " »", etc.); but there are certainly people who do that. NWP should be able to deal with this kind of files too...

Best regard,

Nobumi Iyanaga

Re: macro to delete "tracks" containing certain characters

Posted: 2017-07-23 09:01:53
by phspaelti
Hello Nobumi,
Nobumi Iyanaga wrote:Philip's codes seem very interesting, but I don't understand how they should be inserted in Martin's macro.
I had a more careful look at Martin's code, and I see that he doesn't make use of the find on the added text after all. He really just checks for presence of the find text. So the change to the macro is really simple:

Martin's code:

Code: Select all

	If $isSearchAdditions
		$markedText = $change.markedText
		If $markedText
			$markedRange = $change.markedTextRange
			If $markedRange
				$select = TextSelection.new($markedText, $markedRange)
				$doc.setSelection($select)
				If Find $findText, "s$findOps"
					$isMatch = @TRUE
				End
			End
		End
	End
Changed code:

Code: Select all

	If $isSearchAdditions
		$markedText = $change.markedText
		If $markedText
			$markedRange = $change.markedTextRange
			If $markedRange
				$addedText = $markedText.subtextInRange($markedRange)
				$isMatch = $addedText.find($findText, $findOps)
			End
		End
	End
Here is a copy of the macro with the change included.

[The extension nwm has been deactivated and can no longer be displayed.]

Nobumi Iyanaga wrote: Anyway, I find that it is rather not very intelligent to record these kinds of "Replace All" in track changes (for example Replace All every space with a non-breaking-space for cases like "« " or " »", etc.); but there are certainly people who do that. NWP should be able to deal with this kind of files too...
This problem strikes me as the fundamental problem with Tracked Changes and why I never use them in the first place. The machine simply has no way to know the difference between a meaningful change and a cosmetic change. So unless you constantly weed through the changes and accept the cosmetic ones you end up with a document heavy with changes, and you end up with a "needle in the haystack" problem. Managing the changes can be more work than is gained by tracking them.