Exemplo n.º 1
0
        public override void Execute()
        {
            commandsByRanges.Clear();
            var prevSelection = range.Clone();
            var iChar         = -1;
            var iStartLine    = prevSelection.Start.iLine;
            var iEndLine      = prevSelection.End.iLine;

            ts.CurrentTB.Selection.ColumnSelectionMode = false;
            ts.CurrentTB.Selection.BeginUpdate();
            ts.CurrentTB.BeginUpdate();
            ts.CurrentTB.AllowInsertRemoveLines = false;
            try
            {
                if (cmd is InsertTextCommand)
                {
                    ExecuteInsertTextCommand(ref iChar, (cmd as InsertTextCommand).InsertedText);
                }
                else if (cmd is InsertCharCommand && (cmd as InsertCharCommand).c != '\x0' &&
                         (cmd as InsertCharCommand).c != '\b') //if not DEL or BACKSPACE
                {
                    ExecuteInsertTextCommand(ref iChar, (cmd as InsertCharCommand).c.ToString());
                }
                else
                {
                    ExecuteCommand(ref iChar);
                }
            }
            catch (ArgumentOutOfRangeException)
            {
            }
            finally
            {
                ts.CurrentTB.AllowInsertRemoveLines = true;
                ts.CurrentTB.EndUpdate();

                ts.CurrentTB.Selection = range;
                if (iChar >= 0)
                {
                    ts.CurrentTB.Selection.Start = new Place(iChar, iStartLine);
                    ts.CurrentTB.Selection.End   = new Place(iChar, iEndLine);
                }

                ts.CurrentTB.Selection.ColumnSelectionMode = true;
                ts.CurrentTB.Selection.EndUpdate();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns union with other range.
        /// </summary>
        /// <param name="range"></param>
        /// <returns></returns>
        public Range GetUnionWith(Range range)
        {
            Range r1 = this.Clone();
            Range r2 = range.Clone();

            r1.Normalize();
            r2.Normalize();
            Place newStart = r1.Start < r2.Start ? r1.Start : r2.Start;
            Place newEnd   = r1.End > r2.End ? r1.End : r2.End;

            return(tb.GetRange(newStart, newEnd));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Returns intersection with other range,
        /// empty range returned otherwise
        /// </summary>
        /// <param name="range"></param>
        /// <returns></returns>
        public Range GetIntersectionWith(Range range)
        {
            Range r1 = this.Clone();
            Range r2 = range.Clone();

            r1.Normalize();
            r2.Normalize();
            Place newStart = r1.Start > r2.Start ? r1.Start : r2.Start;
            Place newEnd   = r1.End < r2.End ? r1.End : r2.End;

            if (newEnd < newStart)
            {
                return(new Range(tb, start, start));
            }
            return(tb.GetRange(newStart, newEnd));
        }
Exemplo n.º 4
0
 private void fctb_SelectionChangedDelayed(object sender, EventArgs e)
 {
     //here we draw shortcut for selection area
     FastColoredTextBoxNS.Range selection = fctb.Selection;
     //clear previous shortcuts
     fctb.VisibleRange.ClearStyle(shortCutStyle);
     //create shortcuts
     if (!selection.IsEmpty)//user selected one or more chars?
     {
         //find last char
         var r = selection.Clone();
         r.Normalize();
         r.Start = r.End; //go to last char
         r.GoLeft(true);  //select last char
         //apply ShortCutStyle
         r.SetStyle(shortCutStyle);
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Returns intersection with other range,
        /// empty range returned otherwise
        /// </summary>
        /// <param name="range"></param>
        /// <returns></returns>
        public virtual Range GetIntersectionWith(Range range)
        {
            if (ColumnSelectionMode)
            {
                return(GetIntersectionWith_ColumnSelectionMode(range));
            }

            Range r1 = this.Clone();
            Range r2 = range.Clone();

            r1.Normalize();
            r2.Normalize();
            Place newStart = r1.Start > r2.Start ? r1.Start : r2.Start;
            Place newEnd   = r1.End < r2.End ? r1.End : r2.End;

            if (newEnd < newStart)
            {
                return(new Range(tb, start, start));
            }
            return(tb.GetRange(newStart, newEnd));
        }
Exemplo n.º 6
0
        public virtual void FindPrevious(string pattern)
        {
            List <Range> ranges = null;
            Place        end;

            try
            {
                RegexOptions opt = cbMatchCase.Checked ? RegexOptions.None : RegexOptions.IgnoreCase;/*match case*/

                if (cbWholeWord.Checked)
                {
                    pattern = "\\b" + pattern + "\\b";/*match all*/
                }
                //
                Range range = tb.Selection.Clone();
                range.Normalize();

                //get count
                Range rangetmp = range.Clone();
                rangetmp.Start = new Place(0, 0);
                rangetmp.End   = new Place(tb.GetLineLength(tb.LinesCount - 1), tb.LinesCount - 1);
                int total = rangetmp.GetRangesByLines(pattern, opt).Count();

                //
                end         = range.Start;
                range.Start = new Place(0, 0);
                range.End   = end;
                //
                ranges = new List <Range>(range.GetRangesByLines(pattern, opt));
                ShowFindInfo(total, total - ranges.Count());

                ranges.Reverse();
                foreach (Range r in ranges)
                {
                    tb.Selection = r;
                    tb.DoSelectionVisible();
                    tb.Invalidate();
                    return;
                }
                //
                range.Start = range.End;
                range.End   = new Place(tb.GetLineLength(tb.LinesCount - 1), tb.LinesCount - 1);
                //
                ranges = new List <Range>(range.GetRangesByLines(pattern, opt));
                ShowFindInfo(total, total - ranges.Count());

                ranges.Reverse();
                foreach (Range r in ranges)
                {
                    tb.Selection = r;
                    tb.DoSelectionVisible();
                    tb.Invalidate();
                    return;
                }
                //this.Title = "Not found";
            }
            catch (Exception ex)
            {
                //this.Title = ex.Message;
            }
        }
Exemplo n.º 7
0
        public bool Find(string pattern)
        {
            try
            {
                RegexOptions opt = cbMatchCase.Checked ? RegexOptions.None : RegexOptions.IgnoreCase;
                if (!cbRegex.Checked)
                {
                    pattern = Regex.Escape(pattern);
                }
                if (cbWholeWord.Checked)
                {
                    pattern = "\\b" + pattern + "\\b";
                }
                //
                Range range = tb.Selection.Clone();
                range.Normalize();

                //get count
                Range rangetmp = range.Clone();
                rangetmp.Start = new Place(0, 0);
                rangetmp.End   = new Place(tb.GetLineLength(tb.LinesCount - 1), tb.LinesCount - 1);
                int total = rangetmp.GetRangesByLines(pattern, opt).Count();

                //
                if (firstSearch)
                {
                    startPlace  = range.Start;
                    firstSearch = false;
                }
                //
                range.Start = range.End;
                if (range.Start >= startPlace)
                {
                    range.End = new Place(tb.GetLineLength(tb.LinesCount - 1), tb.LinesCount - 1);
                }
                else
                {
                    range.End = startPlace;
                }
                //
                IEnumerable <Range> ranges = range.GetRangesByLines(pattern, opt);
                ShowFindInfo(total, total - ranges.Count());
                foreach (var r in ranges)
                {
                    tb.Selection = r;
                    tb.DoSelectionVisible();
                    tb.Invalidate();
                    return(true);
                }
                //
                if (range.Start >= startPlace && startPlace > Place.Empty)
                {
                    tb.Selection.Start = new Place(0, 0);
                    Find(pattern);
                    return(true);
                }
                tb.Selection.Start = new Place(0, 0);
                //this.Title = "Not found";
            }
            catch (Exception ex)
            {
                //this.Title = ex.Message;
            }

            return(true);
        }