This project is read-only.

Clearing indicators

Apr 15, 2009 at 12:05 AM
I have set a squiggle indicator for a range and have it working.

How do I clear the indicator?

May 6, 2009 at 7:50 PM

Something like below to clear all indicators. Or you can give it your own range to clear just within that range.

ActiveDocument.Scintilla.NativeInterface.IndicatorClearRange(0, ActiveDocument.Scintilla.Text.Length)

May 6, 2009 at 8:52 PM
Note that IndicatorClearRange() uses the "Current" indicator set by SetIndicatorCurrent() which means it will only clear the last indicator you set.

If you want to avoid using the NativeInterface you can use the ClearIndicator() method off the Range object:

ActiveDocument.Scintilla.GetRange().ClearIndicator(0); // Clears indicator 0 on entire document
ActiveDocument.Scintilla.Selection.Range.ClearIndicator(0); // Clears indicator 0 on current selection

Also the Indicator object itself has some useful search methods for finding ranges that have the given indicator set:
scintilla.Indicators[0].Search(scintilla.GetRange(), scintilla.GetRange(scintilla.CurrentPos)).ClearIndicator(0);

The above finds the next range with indicator 0 set and then clears it. That syntax is pretty cumbersome and should be replaced by a SearchNext() type method defined on the Indicator class

        public Range SearchNext(Range startingAfterRange)
            int start = startingAfterRange.End;
            if (start > NativeScintilla.GetTextLength())
                return null;

            int foundStart = NativeScintilla.IndicatorEnd(_number, start);
            int foundEnd = NativeScintilla.IndicatorEnd(_number, foundStart);
            if (foundStart < 0 || foundStart == foundEnd)
                return null;

            return new Range(foundStart, foundEnd, Scintilla);

        public Range SearchNext(int startingAfterPosition)
            return SearchNext(Scintilla.GetRange(startingAfterPosition));

        public Range SearchNext()
            return SearchNext(Scintilla.GetRange(Scintilla.CurrentPos));