Exemplo n.º 1
0
        /// <summary>
        ///     Заменяет найденное совпадение.
        /// </summary>
        public void Replace(ITextEditorElement editor)
        {
            var text     = editor.GetText();
            var findWhat = GetFindWhat();

            if (!string.IsNullOrEmpty(text) && !string.IsNullOrEmpty(findWhat))
            {
                var selectedText = editor.GetSelectedText();

                // Если выделен какой-либо текст
                if (!string.IsNullOrEmpty(selectedText))
                {
                    var matchCase = GetMatchCase();
                    var wholeWord = GetWholeWord();

                    // Если выделена фраза для замены
                    if (findWhat.Length == selectedText.Length &&
                        selectedText.FindNextIndexOf(findWhat, 0, matchCase, wholeWord) == 0)
                    {
                        var replaceWith = GetReplaceWith();
                        editor.InsertText(replaceWith);
                    }
                }

                FindNext(editor);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Заменяет все найденные совпадения.
        /// </summary>
        public void ReplaceAll(ITextEditorElement editor)
        {
            var text     = editor.GetText();
            var findWhat = GetFindWhat();

            if (!string.IsNullOrEmpty(text) && !string.IsNullOrEmpty(findWhat))
            {
                var matchCase   = GetMatchCase();
                var wholeWord   = GetWholeWord();
                var replaceWith = GetReplaceWith();

                text = text.Replace(findWhat, replaceWith, matchCase, wholeWord);

                editor.SetText(text);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Находит и выделяет следующее совпадение.
        /// </summary>
        public void FindNext(ITextEditorElement editor)
        {
            var text     = editor.GetText();
            var findWhat = GetFindWhat();

            if (!string.IsNullOrEmpty(text) && !string.IsNullOrEmpty(findWhat))
            {
                var matchCase = GetMatchCase();
                var wholeWord = GetWholeWord();

                var index = text.FindNextIndexOf(findWhat, editor.GetCaretOffset(), matchCase, wholeWord);

                if (index < 0)
                {
                    index = text.FindNextIndexOf(findWhat, 0, matchCase, wholeWord);
                }

                if (index >= 0)
                {
                    editor.SelectText(index, findWhat.Length);
                }
            }
        }