This is character by character splits the selected frame to the blocks with the same formatting and then search/replace in these blocks. "The same formatting" is checked on the 4th parameters (font family, size, style, color). The boundaries between the blocks falls out of the search area. It works slowly. function repl (reStr, replacer) { var re = new RegExp (reStr, 'gmi'); var frm = selection[0]; var a, b, i = 0, txtOrig, txtModif; frm.textRange.characters.select (); for (; ; i++) { try { a = frm.textRange.characters; b = frm.textRange.characters[i + 1]; } catch (e) { _replRng (); break; } if (_cmprTxtAttr (a, b)) { b.select (true); continue; } else { _replRng (); i += txtModif.length - txtOrig.length; frm.textRange.characters[i + 1].select (); continue; } } function _replRng () { // nothing return; only modify global vars if (frm.textSelection.length > 1) { txtOrig = frm.textSelection[0].contents + frm.textSelection[1].contents; txtModif = txtOrig.replace (re, replacer); frm.textSelection[1].contents = txtModif.slice (-1); frm.textSelection[0].contents = txtModif.slice (0, -1); } else { txtOrig = frm.textSelection[0].contents; txtModif = txtOrig.replace (re, replacer); frm.textSelection[0].contents = txtModif; } } function _cmprTxtAttr (a, b) { return __compareFill (a, b) && __compareFont (a, b); function __compareFill (a, b) { var aCol = a.characterAttributes.fillColor; var bCol = b.characterAttributes.fillColor; if (aCol.typename != bCol.typename) return false; if (aCol.typename == 'RGBColor') { if (aCol.red != bCol.red || aCol.green != bCol.green || aCol.blue != bCol.blue) { return false; } } else if (aCol.typename == 'CMYKColor') { if (aCol.cyan != bCol.cyan || aCol.magenta != bCol.magenta || aCol.yellow != bCol.yellow || aCol.black != bCol.black) { return false; } } return true; } function __compareFont (a, b) { var aFnt = a.characterAttributes; var bFnt = b.characterAttributes; if (aFnt.size != bFnt.size) return false; if (aFnt.textFont.style != bFnt.textFont.style) return false; if (aFnt.textFont.family != bFnt.textFont.family) return false; return true; } } }
... View more