예제 #1
0
 private void ApplyAutocomplete(AutocompleteItem item, Range fragment)
 {
     string newText = item.GetTextForReplace();
     //replace text of fragment
     fragment.Text = newText;
     fragment.TargetWrapper.TargetControl.Focus();
 }
예제 #2
0
        private Range GetFragment(string searchPattern)
        {
            ITextBoxWrapper tb = TargetControlWrapper;

            if (tb.SelectionLength > 0) return new Range(tb);

            string text = tb.Text;
            var regex = new Regex(searchPattern);
            var result = new Range(tb);

            int startPos = tb.SelectionStart;
            //go forward
            int i = startPos;
            while (i >= 0 && i < text.Length)
            {
                if (!regex.IsMatch(text[i].ToString()))
                    break;
                i++;
            }
            result.End = i;

            //go backward
            i = startPos;
            while (i > 0 && (i - 1) < text.Length)
            {
                if (!regex.IsMatch(text[i - 1].ToString()))
                    break;
                i--;
            }
            result.Start = i;

            return result;
        }