Select() public method

Selects the specified text section.
public Select ( int start, int length ) : void
start int
length int
return void
        public void Set(TextEditor textEditor, IEnumerable<MulticastMessageViewModel> collection)
        {
            _ranges.Clear();

            var document = new StringBuilder();
            var settings = new List<CustomElementSetting>();

            foreach (var target in collection)
            {
                int startOffset = document.Length;

                {
                    string item1;
                    if (target.Option.State.HasFlag(MulticastMessageState.IsLocked)) item1 = "#";
                    else if (target.Option.State.HasFlag(MulticastMessageState.IsUnread)) item1 = "!";
                    else item1 = "@";

                    var item2 = target.Item.CreationTime.ToLocalTime().ToString(LanguagesManager.Instance.DateTime_StringFormat, System.Globalization.DateTimeFormatInfo.InvariantInfo);
                    var item3 = target.Item.Signature;

                    {
                        settings.Add(new CustomElementSetting("State", document.Length, item1.Length));
                        document.Append(item1);
                        document.Append(" ");

                        settings.Add(new CustomElementSetting("CreationTime", document.Length, item2.Length));
                        document.Append(item2);
                        document.Append(" - ");

                        settings.Add(new CustomElementSetting("Signature", document.Length, item3.Length));
                        document.Append(item3);

                        if (!Inspect.ContainTrustSignature(target.Item.Signature))
                        {
                            document.Append(" +");
                            document.Append(target.Option.Cost);
                        }
                    }

                    document.AppendLine();
                }

                {
                    document.AppendLine();
                }

                {
                    foreach (var line in target.Item.Comment
                        .Trim('\r', '\n')
                        .Split(new string[] { "\r\n", "\r", "\n" }, StringSplitOptions.None)
                        .Take(128))
                    {
                        foreach (var match in _uriRegexes.Select(n => n.Matches(line)).SelectMany(n => n.OfType<Match>()))
                        {
                            settings.Add(new CustomElementSetting("Uri", document.Length + match.Index, match.Length));
                        }

                        document.AppendLine(line);
                    }
                }

                {
                    document.AppendLine();
                }

                _ranges.Add(new CustomElementRange(startOffset, document.Length));
            }

            if (document.Length >= 2) document.Remove(document.Length - 2, 2);

            textEditor.Document.BeginUpdate();

            textEditor.Document.Text = "";
            textEditor.CaretOffset = 0;
            textEditor.SelectionLength = 0;
            textEditor.TextArea.TextView.ElementGenerators.Clear();
            textEditor.ScrollToHome();

            textEditor.Document.Text = document.ToString();

            var elementGenerator = new CustomElementGenerator(settings);
            elementGenerator.ClickEvent += (string text) => this.OnClickEvent(text);
            elementGenerator.SelectEvent += (CustomElementRange range) => textEditor.Select(range.Start, range.End - range.Start);
            textEditor.TextArea.TextView.ElementGenerators.Add(elementGenerator);

            textEditor.Document.EndUpdate();

            textEditor.CaretOffset = textEditor.Document.Text.Length;
            textEditor.TextArea.Caret.BringCaretToView();
            textEditor.ScrollToEnd();
        }
Exemplo n.º 2
0
        public void FindTextInTextEditor(TextEditor te)
        {
            if (tbFind.Text.Length == 0) return;
            //         if (cbFindUp.IsChecked == false) G.CurOffset = te.SelectionStart;
            //          else G.CurOffset = te.SelectionStart + te.SelectionLength;
            string stext = tbFind.Text;
            if (cbMatchCase.IsChecked == false) stext = stext.ToLower();
            //    if (cbMatchWholeWord.IsChecked == true) stext = ' ' + stext + ' ';
            if (cbFindUp.IsChecked == false) //Find down
            {
                while (true)
                {
                    DocumentLine dl = te.Document.GetLineByOffset(G.CurOffset);
                    string str = te.Document.GetText(G.CurOffset, dl.Length - (G.CurOffset - dl.Offset));
                    if (cbMatchCase.IsChecked == false) str = str.ToLower();
                    int pos;

                    pos = str.IndexOf(stext);
                    if (pos != -1)
                    {
                    }
                    if (cbMatchWholeWord.IsChecked == true)
                        if (!G.LineConsist(str.Split(' '), stext)) pos = -1;
                    if (pos != -1)
                    {
                        te.ScrollToLine(dl.LineNumber);
                        te.Select(dl.Offset + pos, stext.Length);
                        G.CurOffset = dl.Offset + dl.TotalLength; ;
                        break;
                    }


                    G.CurOffset = dl.Offset + dl.TotalLength;
                    if (G.CurOffset >= te.Document.TextLength) { MessageBox.Show("Reached end of document."); G.CurOffset = 0; break; }
                }//for                             
            }
            else // Find up
            {
                while (true)
                {
                    DocumentLine dl = te.Document.GetLineByOffset(G.CurOffset);
                    string str = te.Document.GetText(dl.Offset, G.CurOffset - dl.Offset);
                    if (cbMatchCase.IsChecked == false) str = str.ToLower();
                    int pos = str.IndexOf(stext);
                    if (pos != -1)
                    {
                        te.ScrollToLine(dl.LineNumber);
                        te.Select(dl.Offset + pos, stext.Length);
                        G.CurOffset = dl.Offset + pos;
                        break;
                    }//if 
                    if (dl.PreviousLine != null)
                        G.CurOffset = dl.PreviousLine.Offset + dl.PreviousLine.Length;
                    else G.CurOffset = 0;
                    if (G.CurOffset <= 0) { MessageBox.Show("Reached begin of document."); G.CurOffset = 0; break; }
                }//for                             

            }
        }//func
Exemplo n.º 3
0
        private void MoveCaretToSource(SegmentLocation loc, ICSharpCode.AvalonEdit.TextEditor editor, bool selectText = true, int?tabToSelect = null)
        {
            if (loc != null)
            {
                var start = loc.Start.Offset;
                var end   = loc.End.Offset;
                editor.ScrollToLine(editor.Document.GetLocation(start).Line);

                if (selectText)
                {
                    editor.Select(start, end - start + 1);
                }

                if (tabToSelect.HasValue)
                {
                    MainTabs.SelectedIndex = tabToSelect.Value;
                }
            }
            else
            {
                editor.Select(0, 0);
            }
        }
Exemplo n.º 4
0
        //public void ClearLabels()
        //{
        //    var ruleset = editor.SyntaxHighlighting.GetNamedRuleSet("LabelsRuleSet");
        //    ruleset.Rules.Clear();
        //}

        //public void AddLabel(string name)
        //{
        //    var color = editor.SyntaxHighlighting.GetNamedColor("Label");
        //    var ruleset = editor.SyntaxHighlighting.GetNamedRuleSet("LabelsRuleSet");
        //    ruleset.Rules.Add(new HighlightingRule() {
        //        Color = color,
        //        Regex = new Regex($"\\b(?>{Regex.Escape(name)})\\b",
        //            RegexOptions.ExplicitCapture | RegexOptions.CultureInvariant)
        //    });
        //}

        public void SelectLine(int lineNumber)
        {
            // https://geek-questions.github.io/articles/1340178/index.html

            //Get the line number based off the offset.
            var line = editor.Document.GetLineByNumber(lineNumber);

            //Select the text.
            editor.Select(line.Offset, line.Length);
            //Scroll the textEditor to the selected line.
            var visualTop = editor.TextArea.TextView.GetVisualTopByDocumentLine(lineNumber);

            editor.ScrollToVerticalOffset(visualTop);
        }
Exemplo n.º 5
0
        private void ReplaceAll(TextEditor editor)
        {
            if (this.cboReplace.Text == null)
            {
                MessageBox.Show("No Replace Text specified");
            }

            int origPos = editor.CaretOffset;

            if (!this.cboLookIn.SelectedValue.ToString().Equals("Selection"))
            {
                //Check whether the relevant Text is already selected
                if (this.cboFind.Text != null && !this.cboFind.Text.Equals(String.Empty))
                {
                    if (this.cboFind.Text.Equals(editor.SelectedText))
                    {
                        //If it is remove the selection so the FindNext() call will simply find the currently highlighted text
                        editor.SelectionStart = 0;
                        editor.SelectionLength = 0;
                    }
                }
            }

            //Replace All works over the entire document unless there was already a selection present
            int minPos, maxPos;
            bool restoreSelection = false;
            if (editor.SelectionLength > 0 && this.IsScopeSelection)
            {
                restoreSelection = true;
                minPos = editor.SelectionStart - 1;
                maxPos = editor.SelectionStart + editor.SelectionLength;
                editor.CaretOffset = Math.Max(minPos, 0);
            }
            else
            {
                minPos = -1;
                maxPos = editor.Text.Length;
                editor.CaretOffset = 0;
            }
            editor.SelectionStart = 0;
            editor.SelectionLength = 0;

            editor.Document.BeginUpdate();
            String replace = this.cboReplace.Text;
            while (this.FindNext(editor, minPos, maxPos))
            {
                int diff = replace.Length - editor.SelectionLength;

                editor.Document.Replace(editor.SelectionStart, editor.SelectionLength, replace);
                editor.SelectionLength = replace.Length;
                editor.CaretOffset = editor.SelectionStart;

                maxPos += diff;
            }
            editor.Document.EndUpdate();

            editor.CaretOffset = origPos;
            editor.ScrollToLine(editor.Document.GetLineByOffset(origPos).LineNumber);

            if (restoreSelection)
            {
                editor.Select(minPos + 1, maxPos - minPos - 1);
            }
        }
Exemplo n.º 6
0
 public static void HighlightText(TextEditor te, int nl)
 {
     DocumentLine dl = te.Document.GetLineByNumber(nl);
     te.UpdateLayout();
     te.Select(dl.Offset, dl.Length);
     te.ScrollToLine(nl);
 }
Exemplo n.º 7
0
 public static void ChangeCpointInCurrentFrame(TextEditor te, int kind, int x, int y)
 {
     if (te == null) return;
     DocumentLine line = te.Document.GetLineByOffset(te.CaretOffset);
     int index = WhatFrameFromLineNumber(te.oi as ObjectInfo, line.LineNumber);
     if (index == -1) return;
     ObjectInfo oi = te.oi as ObjectInfo;
     if (kind!=int.MaxValue)
     ChangeValuesInTagOrAdd(ref oi.data.frames[index].cpoint, "kind:", kind.ToString());
     ChangeValuesInTagOrAdd(ref oi.data.frames[index].cpoint, "x:", x.ToString());
     ChangeValuesInTagOrAdd(ref oi.data.frames[index].cpoint, "y:", y.ToString());
     string text = space3 + "cpoint:" + Environment.NewLine +
                   space6 + ListPropDescToString(oi.data.frames[index].cpoint) + Environment.NewLine +
                   space3 + "cpoint_end:" + Environment.NewLine;
     if (oi.data.frames[index].lnst.ol_cpoint != -1)
     {
         List<PropDesc> lpd = oi.data.frames[index].cpoint;
         DocumentLine dlFirst = te.Document.Lines[oi.data.frames[index].lnst.ol_cpoint - 1];
         int lcount = oi.data.frames[index].lnst.cl_cpoint - oi.data.frames[index].lnst.ol_cpoint;
         te.Document.Replace(dlFirst.Offset, LenghtForGivenLinesCount(dlFirst, lcount), text);
         te.Select(dlFirst.Offset, 0);
     }
     else
     {
         DocumentLine dl = te.Document.Lines[oi.data.frames[index].lastheaderline];
         te.Document.Insert(dl.Offset, text);
         te.Select(dl.Offset, 0);
     }
 }
Exemplo n.º 8
0
 public static void ChangeBpointInCurrentFrame(TextEditor te, int x, int y)
 {
     if (te == null) return;
     DocumentLine line = te.Document.GetLineByOffset(te.CaretOffset);
     int index = WhatFrameFromLineNumber(te.oi as ObjectInfo, line.LineNumber);
     if (index == -1) return;
     string text =
     space3 + "bpoint:" + Environment.NewLine + space6 + "x: " + x.ToString() + space2 + "y: " + y.ToString() + Environment.NewLine + space3 + "bpoint_end:" + Environment.NewLine;
     ObjectInfo oi = te.oi as ObjectInfo;
     if (oi.data.frames[index].lnst.ol_bpoint != -1)
     {
         DocumentLine dlFirst = te.Document.Lines[oi.data.frames[index].lnst.ol_bpoint - 1];
         int lcount = oi.data.frames[index].lnst.cl_bpoint - oi.data.frames[index].lnst.ol_bpoint;
         te.Document.Replace(dlFirst.Offset, LenghtForGivenLinesCount(dlFirst, lcount), text);
         te.Select(dlFirst.Offset, 0);
     }
     else
     {
         DocumentLine dl = te.Document.Lines[oi.data.frames[index].lastheaderline];
         te.Document.Insert(dl.Offset, text);
         te.Select(dl.Offset, 0);              
     }
 }
Exemplo n.º 9
0
 public static void ChangePicInCurrentFrame(TextEditor te, int pic)
 {
     if (te == null) return;
     DocumentLine line = te.Document.GetLineByOffset(te.CaretOffset);
     int index = WhatFrameFromLineNumber(te.oi as ObjectInfo, line.LineNumber);
     if (index == -1) return;
     ObjectInfo oi = te.oi as ObjectInfo;
     ChangeValuesInTagOrAdd(ref oi.data.frames[index].header, "pic:", pic.ToString());
     string text = space3 + ListPropDescToString(oi.data.frames[index].header) + Environment.NewLine;
     DocumentLine dlFirst = te.Document.Lines[oi.data.frames[index].oline];
     int lcount = oi.data.frames[index].lastheaderline - oi.data.frames[index].firstheaderline;
     te.Document.Replace(dlFirst.Offset, LenghtForGivenLinesCount(dlFirst, lcount), text);
     te.Select(dlFirst.Offset, 0);
 }
Exemplo n.º 10
0
        private static void PasteRegionableTagInCurrentFrame(TextEditor te, int kind, Rect reg, string tag = "bdy")
        {
            if (te == null) return;
            DocumentLine line = te.Document.GetLineByOffset(te.CaretOffset);
            int index = WhatFrameFromLineNumber(te.oi as ObjectInfo, line.LineNumber);
            if (index == -1) return;
            string text = space3 + tag + ":" + Environment.NewLine + 
                          space6 + "kind: " + kind.ToString() + space2 + "x: " + reg.X.ToString() + space2 + "y: " + reg.Y.ToString() + space2 + "w: " + reg.Width.ToString() + space2 + "h: " + reg.Height.ToString() + Environment.NewLine + 
                          space3 + tag + "_end:" + Environment.NewLine;
            ObjectInfo oi = te.oi as ObjectInfo;
            List<List<PropDesc>> tagobject = oi.data.frames[index].bdy;
            if (tag == "itr") tagobject = oi.data.frames[index].itr;
            int count = tagobject.Count;

            if (count > 0)
            {
                List<int> cl_tag = oi.data.frames[index].lnst.cl_bdy;
                if (tag == "itr") cl_tag = oi.data.frames[index].lnst.cl_itr;
                int i = cl_tag[count - 1];
                DocumentLine dl = te.Document.GetLineByNumber(i + 1);
                te.Document.Insert(dl.Offset, text);
                te.Select(dl.Offset, 0);
            }
            else
            {
                int i = oi.data.frames[index].cline;
                DocumentLine dl = te.Document.GetLineByNumber(i);
                te.Document.Insert(dl.Offset, text);
                te.Select(dl.Offset, 0);
            }
        }
Exemplo n.º 11
0
 public static void PasteItrInCurrentFrame(TextEditor te, int kind, int effect, Rect itr)
 {
     if (te == null) return;
     DocumentLine line = te.Document.GetLineByOffset(te.CaretOffset);
     int index = WhatFrameFromLineNumber(te.oi as ObjectInfo, line.LineNumber);
     if (index == -1) return;
     string text =
         space3 + "itr:" + Environment.NewLine +
         space6 + "kind: " + kind.ToString() + space2 + "x: " + itr.X.ToString() + space2 + "y: " + itr.Y.ToString() + space2 + "w: " + itr.Width.ToString() + space2 + "h: " + itr.Height.ToString() + space2 + "effect: " + effect.ToString() + Environment.NewLine +
         space3 + "itr_end:" + Environment.NewLine;
     ObjectInfo oi = te.oi as ObjectInfo;
     int count = oi.data.frames[index].itr.Count;
     if (count > 0)
     {
         List<int> cl_tag = oi.data.frames[index].lnst.cl_itr;
         cl_tag = oi.data.frames[index].lnst.cl_itr;
         int i = cl_tag[count - 1];
         DocumentLine dl = te.Document.GetLineByNumber(i + 1);
         te.Document.Insert(dl.Offset, text);
         te.Select(dl.Offset, 0);
     }
     else
     {
         int i = oi.data.frames[index].cline;
         DocumentLine dl = te.Document.GetLineByNumber(i);
         te.Document.Insert(dl.Offset, text);
         te.Select(dl.Offset, 0);
     }
 }
Exemplo n.º 12
0
 public static void ChangeCurrentBdyInCurrentFrame(TextEditor te, int kind, Rect bdy, int bindex)
 {
     if (bdy == Rect.Empty) return;
     if (te == null) return;
     DocumentLine line = te.Document.GetLineByOffset(te.CaretOffset);
     int index = WhatFrameFromLineNumber(te.oi as ObjectInfo, line.LineNumber);
     if (index == -1) return;
     ObjectInfo oi = te.oi as ObjectInfo;
     if (bindex < 0 && bindex >= oi.data.frames[index].bdy.Count) return;
     List<PropDesc> lpd = oi.data.frames[index].bdy[bindex];
     if (kind!=int.MaxValue)
     ChangeValuesInTagOrAdd(ref lpd, "kind:", kind.ToString());
     ChangeValuesInTagOrAdd(ref lpd, "x:", bdy.X.ToString());
     ChangeValuesInTagOrAdd(ref lpd, "y:", bdy.Y.ToString());
     ChangeValuesInTagOrAdd(ref lpd, "w:", bdy.Width.ToString());
     ChangeValuesInTagOrAdd(ref lpd, "h:", bdy.Height.ToString());
     oi.data.frames[index].bdy[bindex] = lpd;
     string text = space3 + "bdy:" + Environment.NewLine +
               space6 + ListPropDescToString(lpd)+ Environment.NewLine +
               space3 + "bdy_end:" + Environment.NewLine;
     if (oi.data.frames[index].lnst.ol_bdy[bindex] != -1)
     {                
         DocumentLine dlFirst = te.Document.Lines[oi.data.frames[index].lnst.ol_bdy[bindex] - 1];
         int lcount = oi.data.frames[index].lnst.cl_bdy[bindex] - oi.data.frames[index].lnst.ol_bdy[bindex];
         te.Document.Replace(dlFirst.Offset, LenghtForGivenLinesCount(dlFirst, lcount), text);
         te.Select(dlFirst.Offset, 0);
     }
 }
Exemplo n.º 13
0
        /// <summary>
        /// Selects a Symbol around the current selection (if any) or caret position
        /// </summary>
        /// <param name="editor">Text Editor</param>
        public void SelectSymbol(TextEditor editor)
        {
            int selStart, selLength;

            if (editor.SelectionStart >= 0 && editor.SelectionLength > 0)
            {
                selStart = editor.SelectionStart;
                selLength = editor.SelectionLength;
            }
            else
            {
                selStart = editor.CaretOffset;
                selLength = 0;
            }

            //If there is an existing Selection and deliminators are not included
            //check whether the preceding and following characters are deiliminators and if so
            //alter the selection start and length appropriately to include these otherwise our
            //select won't select the surrounding symbol properly
            if (selStart > 0 && selLength > 0 && !this._includeDelim)
            {
                if (this.IsStartingDeliminator(editor.Document.GetCharAt(selStart-1)))
                {
                    selStart--;
                    selLength++;
                }
                if (selStart + selLength < editor.Document.TextLength - 1)
                {
                    if (this.IsEndingDeliminator(editor.Document.GetCharAt(selStart + selLength))) selLength++;
                }
            }

            char? endDelim = null;

            //Extend the selection backwards
            while (selStart >= 0)
            {
                selStart--;
                selLength++;

                //Start of Document is always a Boundary
                if (selStart == 0) break;

                //Otherwise check if character at start of selection is a boundary
                char current = editor.Document.GetCharAt(selStart);
                if (this.IsStartingDeliminator(current))
                {
                    endDelim = this.RequireMatchingDeliminator(current);
                    break;
                }
            }
            if (!this._includeDelim)
            {
                if (selStart > 0 || this.IsStartingDeliminator(editor.Document.GetCharAt(selStart)))
                {
                    selStart++;
                    selLength--;
                }
            }

            //Extend the selection forwards
            while (selStart + selLength < editor.Document.TextLength)
            {
                selLength++;

                //End of Document is always a Boundary
                if (selStart + selLength == editor.Document.TextLength) break;

                //Otherwise check if character after end of selection is a boundary
                char current = editor.Document.GetCharAt(selStart + selLength);
                if (endDelim != null )
                {
                    //If a matching End Deliminator is required then stop when that is reached
                    if (endDelim == current) break;
                }
                else if (this.IsEndingDeliminator(current))
                {
                    //Otherwise stop when any End Deliminator is found
                    break;
                }
            }
            if (this._includeDelim)
            {
                selLength++;
            }

            //Select the Symbol Text
            editor.Select(selStart, selLength);
            editor.ScrollToLine(editor.Document.GetLineByOffset(selStart).LineNumber);
        }
Exemplo n.º 14
0
        public bool FindNext(TextEditor editor, int minPos, int maxPos)
        {
            if (editor == null)
            {
                MessageBox.Show("No Text Editor is associated with this Find and Replace Dialog");
                return false;
            }
            if (this.cboFind.Text == null || this.cboFind.Text.Equals(String.Empty))
            {
                MessageBox.Show("No Find Text specified");
                return false;
            }
            String find = this.cboFind.Text;

            //Validate Regex
            if (this.chkRegex.IsChecked == true)
            {
                try
                {
                    Regex.IsMatch(String.Empty, find);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Regular Expression is malformed - " + ex.Message);
                    return false;
                }
            }

            //Add Search Text to Combo Box for later reuse
            if (!this.cboFind.Items.Contains(find))
            {
                this.cboFind.Items.Add(find);
            }

            int start = editor.CaretOffset;
            int pos;
            int length = find.Length;
            StringComparison compareMode = (this.chkMatchCase.IsChecked == true) ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase;
            RegexOptions regexOps = (this.chkMatchCase.IsChecked == true) ? RegexOptions.None : RegexOptions.IgnoreCase;

            if (this.chkSearchUp.IsChecked == true)
            {
                //Search portion of Document prior to current position
                if (this.chkRegex.IsChecked == true)
                {
                    MatchCollection ms = Regex.Matches(editor.Text.Substring(0, start), find, regexOps);
                    if (ms.Count == 0)
                    {
                        pos = -1;
                    }
                    else
                    {
                        pos = ms[ms.Count - 1].Index;
                        length = ms[ms.Count - 1].Length;
                    }
                }
                else
                {
                    pos = editor.Text.Substring(0, start).LastIndexOf(find, compareMode);
                }
            }
            else
            {
                //Search position of Document subsequent to current position (incl. any selected text)
                start += editor.SelectionLength;
                if (this.chkRegex.IsChecked == true)
                {
                    Match m = Regex.Match(editor.Text.Substring(start), find, regexOps);
                    if (!m.Success)
                    {
                        pos = -1;
                    }
                    else
                    {
                        pos = start + m.Index;
                        length = m.Length;
                    }
                }
                else
                {
                    pos = editor.Text.IndexOf(find, start, compareMode);
                }
            }

            //If we've found the position of the next highlight it and return true otherwise return false
            if (pos > -1)
            {
                //Check we meet any document range restrictions
                if (pos < minPos || pos > maxPos)
                {
                    editor.CaretOffset = pos;
                    editor.SelectionStart = pos;
                    editor.SelectionLength = length;
                    return this.FindNext(editor, minPos, maxPos);
                }

                //If Matching on whole word ensure that their are boundaries before and after the match
                if (this.chkMatchWholeWord.IsChecked == true)
                {
                    //Check boundary before
                    if (pos > 0)
                    {
                        char c = editor.Text[pos - 1];
                        if (Char.IsLetterOrDigit(c))
                        {
                            //Not a boundary so adjust start position and recurse
                            editor.CaretOffset = pos + length;
                            if (this.chkSearchUp.IsChecked == false) editor.CaretOffset -= editor.SelectionLength;
                            return this.FindNext(editor);
                        }
                    }
                    //Check boundary after
                    if (pos + length < editor.Text.Length - 1)
                    {
                        char c = editor.Text[pos + length];
                        if (Char.IsLetterOrDigit(c))
                        {
                            //Not a boundary so adjust start position and recurse
                            editor.CaretOffset = pos + length - 1;
                            if (this.chkSearchUp.IsChecked == false) editor.CaretOffset -= editor.SelectionLength;
                            return this.FindNext(editor);
                        }
                    }
                }

                editor.Select(pos, length);
                editor.CaretOffset = pos;
                editor.ScrollTo(editor.Document.GetLineByOffset(pos).LineNumber, 0);
                return true;
            }
            else
            {
                return false;
            }
        }
Exemplo n.º 15
0
 public void Select(int start, int length)
 {
     _editor.Select(start, length);
 }
Exemplo n.º 16
0
        //Highlight symbols start and end
        private void highlightStartEnd(TextEditor rtb)
        {
            int offset = rtb.CaretOffset;
            if (offset < rtb.Text.Length) {
                char[] chStart = { '(', '[', '{' };
                char[] chEnd = { ')', ']', '}' };
                for (int i = 0; i < chStart.Length; i++) {
                    if (rtb.Text.Substring(offset, 1) == chStart[i].ToString()) {
                        rtb.Select(offset, 1);

                        offset = rtb.Text.IndexOf(chEnd[i], offset);
                        rtb.Select(offset, 1);
                        rtb.TextArea.SelectionBrush = new SolidColorBrush(Color.FromRgb(100, 0, 100));
                        break;
                    }
                }
            }
        }
        public void Set(TextEditor textEditor, DateTime creationTime, string signature, int cost, string comment)
        {
            var document = new StringBuilder();
            var settings = new List<CustomElementSetting>();

            {
                {
                    var item1 = "#";
                    var item2 = creationTime.ToLocalTime().ToString(LanguagesManager.Instance.DateTime_StringFormat, System.Globalization.DateTimeFormatInfo.InvariantInfo);
                    var item3 = signature;

                    {
                        settings.Add(new CustomElementSetting("State", document.Length, item1.Length));
                        document.Append(item1);
                        document.Append(" ");

                        settings.Add(new CustomElementSetting("CreationTime", document.Length, item2.Length));
                        document.Append(item2);
                        document.Append(" - ");

                        settings.Add(new CustomElementSetting("Signature", document.Length, item3.Length));
                        document.Append(item3);

                        if (!Inspect.ContainTrustSignature(signature))
                        {
                            document.Append(" - ");
                            document.Append(cost);
                        }
                    }

                    document.AppendLine();
                }

                {
                    document.AppendLine();
                }

                {
                    foreach (var line in comment
                        .Trim('\r', '\n')
                        .Split(new string[] { "\r\n", "\r", "\n" }, StringSplitOptions.None)
                        .Take(128))
                    {
                        foreach (var match in _uriRegexes.Select(n => n.Matches(line)).SelectMany(n => n.OfType<Match>()))
                        {
                            settings.Add(new CustomElementSetting("Uri", document.Length + match.Index, match.Length));
                        }

                        document.AppendLine(line);
                    }
                }

                {
                    document.AppendLine();
                }
            }

            if (document.Length >= 2) document.Remove(document.Length - 2, 2);

            textEditor.Document.BeginUpdate();

            textEditor.Document.Text = "";
            textEditor.CaretOffset = 0;
            textEditor.SelectionLength = 0;
            textEditor.TextArea.TextView.ElementGenerators.Clear();

            textEditor.Document.Text = document.ToString();

            var elementGenerator = new CustomElementGenerator(settings);
            elementGenerator.ClickEvent += (string text) => this.OnClickEvent(text);
            elementGenerator.SelectEvent += (CustomElementRange range) => textEditor.Select(range.Start, range.End - range.Start);
            textEditor.TextArea.TextView.ElementGenerators.Add(new CustomElementGenerator(settings));

            textEditor.Document.EndUpdate();
        }