Show pageOld revisionsBacklinksAdd to bookBack to top This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. ====== Using Text Highlight ====== HippoEDIT scripting API does not support ordinary highlighting of the text ranges with a color. But you can do the same using styles. The example below shows you usage of [[scripting:api:document:add-style-range|AddStyleRange]] and [[scripting:api:document:remove-style-ranges|RemoveStyleRanges]] for adding and removing text highlights. <file javascript highlighting.hejs> var doc = ActiveDocument; var sel = new Range(0, 0, doc.LineCount - 1, doc.GetLineLength(doc.LineCount - 1)); var output = Application.Output("Test Output"); var results = doc.FindAll("test", 0, sel); var styleHigligh = new Style("my_highlighting", "Highlighting", "My Highlighting Style"); styleHigligh.BoxColor = "Error"; styleHigligh.BoxStyle = eBoxStyleRoundRect; output.writeln("Find all \"test\" matches in current document (" + results.length + "):"); for (var i = 1, len = results.length; i <= len; i++) { output.writeln("Line : " + results[i].Top + ", Pos : " + results[i].Left); doc.AddStyleRange(results[i], styleHigligh); } doc.RemoveStyleRanges(null, styleHigligh); </file> <file javascript highlighting2.hejs> // create the highlighting style, remember, it is alive whole editor session var styleHighlight = new Style("my_highlighting", "Highlighting", "My Highlighting Style"); //styleHighlight.ForeColor = "#FF0000"; styleHighlight.BackColor = "#FFFF00"; function Highlight1() { // get current cursor position var posAbs = ActiveDocument.TextToAbsolute(ActiveView.Position); // create range including two characters before and two after var posStart = ActiveDocument.AbsoluteToText(posAbs - 2); var posEnd = ActiveDocument.AbsoluteToText(posAbs + 2); var rangeHighlight = new Range(posStart.Line, posStart.Pos, posEnd.Line, posEnd.Pos); // highlight range with our style ActiveDocument.AddStyleRange(rangeHighlight, styleHighlight); } function Highlight2() { // get current cursor position var posStart = ActiveDocument.MovePosition(ActiveView.Position, -2); var posEnd = ActiveDocument.MovePosition(ActiveView.Position, 2); // create range including two characters before and two after var rangeHighlight = new Range(posStart, posEnd); // highlight range with our style ActiveDocument.AddStyleRange(rangeHighlight, styleHighlight); } Highlight2(); // remove our highlighting sleep(3000); ActiveDocument.RemoveStyleRanges(null, styleHighlight); </file>