Home Forums General XMetaL Discussion Indicating invisible Unicode characters in XMetaL Reply To: Indicating invisible Unicode characters in XMetaL

Derek Read

Reply to: Indicating invisible Unicode characters in XMetaL

Here's another version of a script that ultimately does the same thing as the previous one.

The benefit to this one is that the user's selection is not lost. The drawback with it being slow isn't as bad as I thought. You need to have an extreme case for it to be noticable and I'm assuming these chars are probably fairly rarely used even for you (?)

Your users should be able to run this one (along with the reversing version which I have not written) any time and not lose their current selection.

[code]//XMetaL Script Language JScript:
//Same script but using Find.Execute instead of JScript string manipulations.

//Declare a range we can use to manipulate the doc
var rng     = ActiveDocument.Range;

//Put hex values representing the chars we want to convert to PIs into an array
var chars   = [“2060″,”200B”,”00A0″];

//Using rng.Delete() causes the document to be updated.
//Turn off the rendering engine until after this loop to reduce flicker and speed things up.
ActiveDocument.FormattingUpdating = false;

//Loop once for each character in the array
for(i=0;i //Move the range to the start of the doc so we will find all chars
//convert the value from the array to a character
var char = String.fromCharCode(parseInt(chars,16));
//Keep going as long as we can find the char
//Next line is needed because inserting a PI doesn't replace the current selection (like other insertion actions)
//Delete the char
//Insert a PI
//Give the PI a target that matches the character's Unicode code point value for easy identification
//Turn the rendering engine back on.
ActiveDocument.FormattingUpdating = true;[/code]