// Use the dialog configuration to replace all matches.
        private List <CharacterRange> ReplaceAllWrapper()
        {
            var results = _manager.ReplaceAll(GetQuery(), SanitizeText(txtReplace.Text), false, false);

            ReplaceAllResults?.Invoke(this, new ReplaceResultsEventArgs(_manager, results));
            return(results);
        }
Beispiel #2
0
        public List <CharacterRange> ReplaceAll(int startPos, int endPos, string searchString, string replaceString, SearchFlags flags, bool mark, bool highlight)
        {
            var results = new List <CharacterRange>();

            Scintilla.IndicatorCurrent = Indicator.Index;

            var findCount = 0;
            var lastLine  = -1;

            Scintilla.BeginUndoAction();

            var diff = replaceString.Length - searchString.Length;

            while (true)
            {
                var r = Find(startPos, endPos, searchString, flags);
                if (r.MinPosition == r.MaxPosition)
                {
                    break;
                }

                Scintilla.SelectionStart = r.MinPosition;
                Scintilla.SelectionEnd   = r.MaxPosition;
                Scintilla.ReplaceSelection(replaceString);
                r       = new CharacterRange(r.MinPosition, startPos = r.MinPosition + replaceString.Length);
                endPos += diff;

                results.Add(r);
                findCount++;

                if (mark)
                {
                    //	We can of course have multiple instances of a find on a single
                    //	line. We don't want to mark this line more than once.
                    var line = new Line(Scintilla, Scintilla.LineFromPosition(r.MinPosition));
                    if (line.Position > lastLine)
                    {
                        line.MarkerAdd(Marker.Index);
                    }
                    lastLine = line.Position;
                }
                if (highlight)
                {
                    Scintilla.IndicatorFillRange(r.MinPosition, r.MaxPosition - r.MinPosition);
                }
            }

            Scintilla.EndUndoAction();

            ReplaceAllResults?.Invoke(this, new ResultsEventArgs(new FindResults(results)));

            return(results);
        }
Beispiel #3
0
        public List <CharacterRange> ReplaceAll(CharacterRange rangeToSearch, Regex findExpression, string replaceExpression, bool mark, bool highlight)
        {
            var results = new List <CharacterRange>();

            Scintilla.IndicatorCurrent = Indicator.Index;

            var lastLine = -1;

            Scintilla.BeginUndoAction();

            while (true)
            {
                var r = Find(rangeToSearch, findExpression);
                if (r.MinPosition == r.MaxPosition)
                {
                    break;
                }

                var findString    = Scintilla.GetTextRange(r.MinPosition, r.MaxPosition - r.MinPosition);
                var replaceString = findExpression.Replace(findString, replaceExpression);
                Scintilla.SelectionStart = r.MinPosition;
                Scintilla.SelectionEnd   = r.MaxPosition;
                Scintilla.ReplaceSelection(replaceString);
                r             = new CharacterRange(r.MinPosition, r.MinPosition + replaceString.Length);
                rangeToSearch = new CharacterRange(r.MaxPosition, rangeToSearch.MaxPosition + replaceString.Length - findString.Length);

                results.Add(r);

                if (mark)
                {
                    //	We can of course have multiple instances of a find on a single
                    //	line. We don't want to mark this line more than once.
                    var line = new Line(Scintilla, Scintilla.LineFromPosition(r.MinPosition));
                    if (line.Position > lastLine)
                    {
                        line.MarkerAdd(Marker.Index);
                    }
                    lastLine = line.Position;
                }
                if (highlight)
                {
                    Scintilla.IndicatorFillRange(r.MinPosition, r.MaxPosition - r.MinPosition);
                }
                rangeToSearch = new CharacterRange(r.MaxPosition, rangeToSearch.MaxPosition);
            }

            Scintilla.EndUndoAction();

            ReplaceAllResults?.Invoke(this, new ResultsEventArgs(new FindResults(results)));

            return(results);
        }