Line index and char index
Exemplo n.º 1
0
        bool CharIsHyperlink(Place place)
        {
            var mask = fctb.GetStyleIndexMask(new Style[] { blueStyle });
            if (place.iChar < fctb.GetLineLength(place.iLine))
                if ((fctb[place].style & mask) != 0)
                    return true;

            return false;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Colorizes the tokens.
        /// </summary>
        /// <param name="editor">The editor.</param>
        /// <param name="registry">The registry.</param>
        /// <param name="tokens">The tokens.</param>
        /// <param name="errorTokens">The error tokens.</param>
        public void ColorizeTokens(FastColoredTextBox editor, IStyleRegistry registry, IList <SyntaxToken> tokens, IList <IToken> errorTokens)
        {
            int coloring = Interlocked.Exchange(ref _TokenColoringInProgress, 1);

            if (coloring != 0)
            {
                return;
            }

            editor.BeginInvoke(
                new MethodInvoker(() =>
            {
                editor.BeginUpdate();

                try
                {
                    foreach (var token in tokens)
                    {
                        var startingPlace = new Place(token.ActualParserToken.Column, token.ActualParserToken.Line - 1);
                        var stoppingPlace = new Place(token.EndingColumnPosition, token.EndingLineNumber - 1);
                        var tokenRange    = editor.GetRange(startingPlace, stoppingPlace);
                        tokenRange.ClearStyle(StyleIndex.All);
                        var style = registry.GetTokenStyle(token);
                        tokenRange.SetStyle(style);
                    }
                    foreach (var token in errorTokens)
                    {
                        var startingPlace = new Place(token.Column, token.Line - 1);
                        var endPlace      = token.GetEndPlace();

                        // We shift the end position one forward so that the range colors correctly.
                        var stoppingPlace = new Place(endPlace.Position + 1, endPlace.Line - 1);

                        var tokenRange = editor.GetRange(startingPlace, stoppingPlace);
                        tokenRange.SetStyle(registry.GetParseErrorStyle());
                    }
                }
                // ReSharper disable once CatchAllClause
                catch (Exception ex)
                {
                    var errorDisplay = new ErrorDisplay
                    {
                        Text            = Resources.TokenColoringErrorTitle,
                        ErrorMessage    = ex.Message,
                        ErrorStackTrace = ex.StackTrace
                    };
                    errorDisplay.ShowDialog();
                }
                finally
                {
                    editor.EndUpdate();
                }

                _TokenColoringInProgress = 0;
            }));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets absolute text position from line and char position
        /// </summary>
        /// <param name="lines"></param>
        /// <param name="point">Line and char position</param>
        /// <returns>Point of char</returns>
        public static int PlaceToPosition(TextSource lines, Place point)
        {
            if (point.iLine < 0 || point.iLine >= lines.Count ||
                point.iChar >= lines[point.iLine].Count + Environment.NewLine.Length)
                return -1;

            int result = 0;
            for (int i = 0; i < point.iLine; i++)
                result += lines[i].Count + Environment.NewLine.Length;
            result += point.iChar;

            return result;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Draws text to given Graphics
        /// </summary>
        /// <param name="gr"></param>
        /// <param name="textbox"></param>
        /// <param name="start">Start place of drawing text</param>
        /// <param name="size">Size of drawing</param>
        public static void DrawText(Graphics gr, FastColoredTextBox textbox, Place start, Size size)
        {
            if (textbox.needRecalc)
                textbox.Recalc();

            if (textbox.needRecalcFoldingLines)
                textbox.RecalcFoldingLines();

            var startPoint = textbox.PlaceToPoint(start);
            var startY = startPoint.Y + textbox.VerticalScroll.Value;
            var startX = startPoint.X + textbox.HorizontalScroll.Value - textbox.LeftIndent - textbox.Paddings.Left;
            // determine range of characters that we can draw
            int firstChar = start.iChar;
            int lastChar = (startX + size.Width) / textbox.CharWidth;

            var startLine = start.iLine;
            //draw text
            for (int iLine = startLine; iLine < textbox.lines.Count; iLine++)
            {
                Line line = textbox.lines[iLine];
                LineInfo lineInfo = textbox.LineInfos[iLine];
                //
                if (lineInfo.startY > startY + size.Height)
                    break;
                if (lineInfo.startY + lineInfo.WordWrapStringsCount * textbox.CharHeight < startY)
                    continue;
                if (lineInfo.VisibleState == VisibleState.Hidden)
                    continue;

                int y = lineInfo.startY - startY;
                //
                gr.SmoothingMode = SmoothingMode.None;
                //draw line background
                if (lineInfo.VisibleState == VisibleState.Visible)
                    if (line.BackgroundBrush != null)
                        gr.FillRectangle(line.BackgroundBrush, new Rectangle(0, y, size.Width, textbox.CharHeight * lineInfo.WordWrapStringsCount));
                //
                gr.SmoothingMode = SmoothingMode.AntiAlias;

                //draw wordwrap strings of line
                for (int iWordWrapLine = 0; iWordWrapLine < lineInfo.WordWrapStringsCount; iWordWrapLine++)
                {
                    y = lineInfo.startY + iWordWrapLine * textbox.CharHeight - startY;
                    //indent
                    var indent = iWordWrapLine == 0 ? 0 : lineInfo.wordWrapIndent * textbox.CharWidth;
                    //draw chars
                    Rendering.DrawLineChars(gr, textbox, firstChar, lastChar, iLine, iWordWrapLine, -startX + indent, y);
                }
            }
        }
Exemplo n.º 5
0
 public void FindNext(string pattern)
 {
     try
     {
         tbFind.BackColor = Color.White;
         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();
         //
         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;
         //
         foreach (var r in range.GetRangesByLines(pattern, opt))
         {
             tb.Selection = r;
             tb.DoSelectionVisible();
             tb.Invalidate();
             return;
         }
         //
         if (range.Start >= startPlace && startPlace > Place.Empty)
         {
             tb.Selection.Start = new Place(0, 0);
             FindNext(pattern);
             return;
         }
         tbFind.BackColor = Color.LightCoral;
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Exemplo n.º 6
0
        public virtual void FindNext(string pattern, bool toBack = false)
        {
            tb.YellowSelection    = true;
            tb.SelectionAfterFind = true;

            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();
                //
                if (firstSearch) {
                    startPlace = range.Start;
                    firstSearch = false;
                }
                //
                range.Start = range.End;
                // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
                if (range.Start >= startPlace)
                    range.End = new Place(tb.GetLineLength(tb.LinesCount - 1), tb.LinesCount - 1);
                else
                    range.End = startPlace;
                //
                foreach (var r in range.GetRangesByLines(pattern, opt)) {
                    tb.Selection = r;
                    tb.DoSelectionVisible();
                    tb.Invalidate();
                    return;
                }
                //
                if (range.Start >= startPlace && startPlace > Place.Empty) {
                    tb.Selection.Start = new Place(0, 0);
                    FindNext(pattern);
                    return;
                }
                firstSearch = true;
                if (FoundCount == 0)
                    MessageBox.Show("Поиск окончен.\r\nНо так и не удалось найти введённый текст :(", MBCaption, MessageBoxButtons.OK, MessageBoxIcon.Information);

            } catch (Exception ex) {
                MessageBox.Show("К сажалению, произолша какая-то ошибка.\r\nБыло бы замечательно сообщить об этом автору.\r\n" + ex.Message, MBCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 7
0
 private void FindNext()
 {
     try
     {
         string pattern = tbFind.Text;
         RegexOptions opt = cbMatchCase.Checked ? RegexOptions.None : RegexOptions.IgnoreCase;
         if (!cbRegex.Checked)
             pattern = Regex.Replace(pattern, RegexSpecSymbolsPattern, "\\$0");
         if (cbWholeWord.Checked)
             pattern = "\\b" + pattern + "\\b";
         //
         Range range = tb.Selection.Clone();
         range.Normalize();
         //
         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;
         //
         foreach (var r in range.GetRanges(pattern, opt))
         {
             tb.Selection = r;
             tb.DoSelectionVisible();
             tb.Invalidate();
             return;
         }
         //
         if (range.Start >= startPlace && startPlace > Place.Empty)
         {
             tb.Selection.Start = new Place(0, 0);
             FindNext();
             return;
         }
         MessageBox.Show("Not found");
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Exemplo n.º 8
0
 public virtual void FindNext(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();
         //
         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;
         //
         foreach (var r in range.GetRangesByLines(pattern, opt))
         {
             tb.Selection = r;
             tb.DoSelectionVisible();
             tb.Invalidate();
             return;
         }
         //
         if (range.Start >= startPlace && startPlace > Place.Empty)
         {
             tb.Selection.Start = new Place(0, 0);
             FindNext(pattern);
             return;
         }
         MessageBox.Show("Совпадений не найдено", MBCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, MBCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Exemplo n.º 9
0
 public virtual void FindNext(string pattern)
 {
     try
     {
         var opt = cbMatchCase.Checked ? RegexOptions.None : RegexOptions.IgnoreCase;
         if (!cbRegex.Checked)
             pattern = Regex.Escape(pattern);
         if (cbWholeWord.Checked)
             pattern = "\\b" + pattern + "\\b";
         //
         var range = _tb.Selection.Clone();
         range.Normalize();
         //
         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;
         //
         foreach (var r in range.GetRangesByLines(pattern, opt))
         {
             _tb.Selection = r;
             _tb.DoSelectionVisible();
             _tb.Invalidate();
             return;
         }
         //
         if (range.Start >= _startPlace && _startPlace > Place.Empty)
         {
             _tb.Selection.Start = new Place(0, 0);
             FindNext(pattern);
             return;
         }
         MessageBox.Show("Not found");
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Exemplo n.º 10
0
        /// <summary>
        /// Place is the target position.
        /// The text is the strign that will be inserted.
        /// </summary>
        /// <param name="textbox"></param>
        /// <param name="place"></param>
        /// <param name="text"></param>
        internal static void DoDragDrop(FastColoredTextBox textbox, Place place, string text)
        {
            Range insertRange = new Range(textbox, place, place);

            // Abort, if insertRange is read only
            if (insertRange.ReadOnly)
                return;

            // Abort, if dragged range contains target place
            if ((textbox.draggedRange != null) && (textbox.draggedRange.Contains(place) == true))
                return;

            if (textbox.draggedRange == null)//drag from outside
            {
                DropFromTheOutside(textbox, place, text);
            }
            else//drag from me
            {
                DropFromTheInside(textbox, place, text);
            }
            textbox.draggedRange = null;
        }
Exemplo n.º 11
0
 bool Find()
 {
     string pattern = tbFind.Text;
     RegexOptions opt = cbMatchCase.Checked ? RegexOptions.None : RegexOptions.IgnoreCase;
     if (!cbRegex.Checked)
         pattern = Regex.Replace(pattern, FastColoredTextBoxNS.FindForm.RegexSpecSymbolsPattern, "\\$0");
     if (cbWholeWord.Checked)
         pattern = "\\b" + pattern + "\\b";
     //
     Range range = tb.Selection.Clone();
     range.Normalize();
     //
     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;
     //
     foreach (var r in range.GetRanges(pattern, opt))
     {
         tb.Selection.Start = r.Start;
         tb.Selection.End = r.End;
         tb.DoSelectionVisible();
         tb.Invalidate();
         return true;
     }
     if (range.Start >= startPlace && startPlace > Place.Empty)
     {
         tb.Selection.Start = new Place(0, 0);
         return Find();
     }
     return false;
 }
Exemplo n.º 12
0
 public bool Find(string pattern)
 {
     var opt = cbMatchCase.Checked ? RegexOptions.None : RegexOptions.IgnoreCase;
     if (!cbRegex.Checked)
         pattern = Regex.Escape(pattern);
     if (cbWholeWord.Checked)
         pattern = "\\b" + pattern + "\\b";
     //
     var range = _tb.Selection.Clone();
     range.Normalize();
     //
     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;
     //
     foreach (var r in range.GetRangesByLines(pattern, opt))
     {
         _tb.Selection.Start = r.Start;
         _tb.Selection.End = r.End;
         _tb.DoSelectionVisible();
         _tb.Invalidate();
         return true;
     }
     if (range.Start >= _startPlace && _startPlace > Place.Empty)
     {
         _tb.Selection.Start = new Place(0, 0);
         return Find(pattern);
     }
     return false;
 }
Exemplo n.º 13
0
        private void Find(string pattern, FindNextDirection direction)
        {
            string originalPattern = pattern;
            Place start = new Place(0,0);
            Place endOfDocument = new Place(tb.GetLineLength(tb.LinesCount - 1), tb.LinesCount - 1);
            try
            {
                // create Regex
                RegexOptions opt = cbMatchCase.Checked ? RegexOptions.None : RegexOptions.IgnoreCase;
                if (!cbRegex.Checked)
                    pattern = Regex.Escape(pattern);
                if (cbWholeWord.Checked)
                    pattern = "\\b" + pattern + "\\b";
                // the current position
                Range range = tb.Selection.Clone();
                range.Normalize();

                // remember the start position
                start = new Place(range.Start.iChar, range.Start.iLine);

                if (direction == FindNextDirection.Next)
                {
                    // search till the end of the document
                    if (this.hasPreviousFindResult)
                    {
                        // increase range.Start with one position (if we don't do this will keep finding the same string)
                        range.Start = NextPlace(start);
                    }
                    else
                    {
                        range.Start = start;
                    }
                    range.End = endOfDocument; // search until end of document
                }
                else // find previous
                {
                    // search backwards till start of document
                    range.Start = new Place(0, 0);
                    range.End = start;
                }

                Place foundMatchPlace;
                bool foundMatch = TryFindNext(pattern, opt, direction, range, out foundMatchPlace);
                if (foundMatch)
                {
                    this.hasPreviousFindResult = true;
                    return;
                }

                // Searching forwarded and started at (0,0) => we have found nothing...
                if (direction == FindNextDirection.Next && start == new Place(0, 0))
                {
                    // Only show message when we don't have a previous find.
                    if (!this.hasPreviousFindResult) MessageBox.Show(String.Format("Pattern {0} not found.", originalPattern));
                    this.hasPreviousFindResult = false;
                    return;
                }
                // Searching backward and started at end of document => we have found nothing
                if (direction == FindNextDirection.Previous && start == endOfDocument)
                {
                    // Only show message when we don't have a previous find.
                    if (!this.hasPreviousFindResult) MessageBox.Show(String.Format("Pattern {0} not found.", originalPattern));
                    this.hasPreviousFindResult = false;
                    return;
                }

                // we haven't searched the entire document

                // Change the search range depending on whether we are searching for the next or previous
                if (direction == FindNextDirection.Next)
                {
                    // search from (0,0) to the line-end of start
                    range.Start = new Place(0, 0);
                    range.End = EndOfLine(start);
                }
                else // find previous
                {
                    // search from document-end to line-start of start
                    range.Start = StartOfLine(start);
                    range.End = endOfDocument; // search until end of document
                }

                Place foundMatchPlace2;
                bool foundMatch2 = TryFindNext(pattern, opt, direction, range, out foundMatchPlace2);
                if (foundMatch2)
                {
                    this.hasPreviousFindResult = true;
                    return;
                }

                // Found nothing
                // Only show message when we don't have a previous find.
                if (!this.hasPreviousFindResult) MessageBox.Show(String.Format("Pattern {0} not found.", originalPattern));
                this.hasPreviousFindResult = false;

            }
            catch (Exception e)
            {
                MessageBox.Show(this, e.Message, "Exception while searching");
            }
        }
Exemplo n.º 14
0
        private static void DropFromTheInside(FastColoredTextBox textbox, Place place, string text)
        {
            Range insertRange = new Range(textbox, place, place);

            // Determine, if the dragged string should be copied or moved
            bool copyMode =
                (textbox.draggedRange == null) ||       // drag from outside
                (textbox.draggedRange.ReadOnly) ||      // dragged range is read only
                ((Control.ModifierKeys & Keys.Control) != Keys.None);

            if (!textbox.draggedRange.Contains(place))
            {
                textbox.BeginAutoUndo();
                textbox.Selection.BeginUpdate();

                //remember dragged selection for undo/redo
                textbox.Selection = textbox.draggedRange;
                textbox.lines.Manager.ExecuteCommand(new SelectCommand(textbox.lines));
                //

                if (textbox.draggedRange.ColumnSelectionMode)
                {
                    // dropping a block selection, add a few new lines
                    textbox.draggedRange.Normalize();
                    var endLine = place.iLine + textbox.draggedRange.End.iLine - textbox.draggedRange.Start.iLine;
                    var end = new Place(place.iChar,endLine );
                    insertRange = new Range(textbox, place, end) { ColumnSelectionMode = true };
                    for (int i = textbox.LinesCount; i <= insertRange.End.iLine; i++)
                    {
                        textbox.Selection.GoLast(false);
                        textbox.InsertChar('\n');
                    }
                }

                if (!insertRange.ReadOnly)
                {
                    if (place < textbox.draggedRange.Start)
                    {
                        // Target place is before the dragged range,
                        // first delete dragged range if not in copy mode
                        if (copyMode == false)
                        {
                            textbox.Selection = textbox.draggedRange;
                            textbox.ClearSelected(); // clear original selectin
                        }

                        // Insert text
                        textbox.Selection = insertRange;
                        textbox.Selection.ColumnSelectionMode = insertRange.ColumnSelectionMode;
                        textbox.InsertText(text);
                    }
                    else
                    {
                        // Target place is after the dragged range, first insert the text
                        // Insert text
                        textbox.Selection = insertRange;
                        textbox.Selection.ColumnSelectionMode = insertRange.ColumnSelectionMode;
                        textbox.InsertText(text);

                        // Delete dragged range if not in copy mode
                        if (copyMode == false)
                        {
                            textbox.Selection = textbox.draggedRange;
                            textbox.ClearSelected();
                        }
                    }
                }

                // Selection start and end position
                Place startPosition = place;
                Place endPosition = textbox.Selection.Start;

                // Correct selection
                Range dR = (textbox.draggedRange.End > textbox.draggedRange.Start)  // dragged selection
                    ? RangeUtil.GetRange(textbox, textbox.draggedRange.Start, textbox.draggedRange.End)
                    : RangeUtil.GetRange(textbox, textbox.draggedRange.End, textbox.draggedRange.Start);
                Place tP = place; // targetPlace
                int tS_S_Line;  // targetSelection.Start.iLine
                int tS_S_Char;  // targetSelection.Start.iChar
                int tS_E_Line;  // targetSelection.End.iLine
                int tS_E_Char;  // targetSelection.End.iChar
                if ((place > textbox.draggedRange.Start) && (copyMode == false))
                {
                    if (textbox.draggedRange.ColumnSelectionMode == false)
                    {
                        // Normal selection mode:

                        // Determine character/column position of target selection
                        if (dR.Start.iLine != dR.End.iLine) // If more then one line was selected/dragged ...
                        {
                            tS_S_Char = (dR.End.iLine != tP.iLine)
                                ? tP.iChar
                                : dR.Start.iChar + (tP.iChar - dR.End.iChar);
                            tS_E_Char = dR.End.iChar;
                        }
                        else // only one line was selected/dragged
                        {
                            if (dR.End.iLine == tP.iLine)
                            {
                                tS_S_Char = tP.iChar - dR.Text.Length;
                                tS_E_Char = tP.iChar;
                            }
                            else
                            {
                                tS_S_Char = tP.iChar;
                                tS_E_Char = tP.iChar + dR.Text.Length;
                            }
                        }

                        // Determine line/row of target selection
                        if (dR.End.iLine != tP.iLine)
                        {
                            tS_S_Line = tP.iLine - (dR.End.iLine - dR.Start.iLine);
                            tS_E_Line = tP.iLine;
                        }
                        else
                        {
                            tS_S_Line = dR.Start.iLine;
                            tS_E_Line = dR.End.iLine;
                        }

                        startPosition = new Place(tS_S_Char, tS_S_Line);
                        endPosition = new Place(tS_E_Char, tS_E_Line);
                    }
                }

                // Select inserted text
                if (!textbox.draggedRange.ColumnSelectionMode)
                {
                    textbox.Selection = new Range(textbox, startPosition, endPosition);
                }
                else
                {
                    if ((copyMode == false) &&
                        (place.iLine >= dR.Start.iLine) && (place.iLine <= dR.End.iLine) &&
                        (place.iChar >= dR.End.iChar))
                    {
                        tS_S_Char = tP.iChar - (dR.End.iChar - dR.Start.iChar);
                        tS_E_Char = tP.iChar;
                    }
                    else
                    {
                        tS_S_Char = tP.iChar;
                        tS_E_Char = tP.iChar + (dR.End.iChar - dR.Start.iChar);
                    }
                    tS_S_Line = tP.iLine;
                    tS_E_Line = tP.iLine + (dR.End.iLine - dR.Start.iLine);

                    startPosition = new Place(tS_S_Char, tS_S_Line);
                    endPosition = new Place(tS_E_Char, tS_E_Line);
                    textbox.Selection = new Range(textbox, startPosition, endPosition)
                        {
                            ColumnSelectionMode = true
                        };
                }

                textbox.Range.EndUpdate();
                textbox.EndAutoUndo();
            }
            textbox.Selection.Inverse();
        }
 public RangeInfo(Range r)
 {
     Start = r.Start;
     End   = r.End;
 }
Exemplo n.º 16
0
 /// <summary>
 /// Get range of text
 /// </summary>
 /// <param name="textbox"></param>
 /// <param name="fromPlace">Line and char position</param>
 /// <param name="toPlace">Line and char position</param>
 /// <returns>Range</returns>
 public static Range GetRange(FastColoredTextBox textbox, Place fromPlace, Place toPlace)
 {
     return new Range(textbox, fromPlace, toPlace);
 }
Exemplo n.º 17
0
        /// <summary>
        /// Wait for line entering.
        /// Set IsReadLineMode to false for break of waiting.
        /// </summary>
        /// <returns></returns>
        public string ReadLine()
        {
            GoEnd();
            StartReadPlace = Range.End;
            IsReadLineMode = true;
            try
            {
                while (IsReadLineMode)
                {
                    Application.DoEvents();
                    Thread.Sleep(5);
                }
            }
            finally
            {
                IsReadLineMode = false;
                ClearUndo();
            }

            return new Range(this, StartReadPlace, Range.End).Text.TrimEnd('\r', '\n');
        }
Exemplo n.º 18
0
 public PrepareOpeningEventArgs(bool cancel, string text, Place startPos)
 {
     Cancel   = cancel;
     Text     = text;
     StartPos = startPos;
 }
Exemplo n.º 19
0
 public FCTBRangeStream(FastColoredTextBoxNS.Range range)
 {
     m_range           = range;
     m_currentPosition = range.Start;
 }
 public static void Select(Place placeStart, Place placeEnd, FastColoredTextBox editor)
 {
     editor.Selection = new Range(editor, placeStart, placeEnd);
     editor.DoCaretVisible();
 }
            public override CompareResult Compare(string fragmentText)
            {
                var r = Parent.Fragment.Clone();
                while (r.Start.iChar > 0)
                {
                    if (r.CharBeforeStart == '}')
                    {
                        enterPlace = r.Start;
                        return CompareResult.Visible;
                    }

                    r.GoLeftThroughFolded();
                }

                return CompareResult.Hidden;
            }
Exemplo n.º 22
0
        public override void Clear()
        {
            var oldIsReadMode = isReadLineMode;

            isReadLineMode = false;
            isUpdating = true;

            base.Clear();

            isUpdating = false;
            isReadLineMode = oldIsReadMode;

            StartReadPlace = Place.Empty;
        }
Exemplo n.º 23
0
        private string findCheckFlagClickedTarget(Place p)
        {
            Match checkflagTargetsMatch = Match(this.editor.GetLineText(p.iLine), @"(?i)(?<=\@checkflag\()([A-z_0-9öäüáéíóú+\s]+)(,([A-z_0-9öäüáéíóú+\s]+))*(?=\))"); //extracting the checkflag specifier

            string foundTarget = null;
            for (int i = checkflagTargetsMatch.Groups[3].Captures.Count - 1; i >= 0 && foundTarget == null; i--)
            {
                if (checkflagTargetsMatch.Groups[3].Captures[i].Index <= p.iChar)
                {
                    foundTarget = checkflagTargetsMatch.Groups[3].Captures[i].Value;
                }
            }

            if (foundTarget == null)
            {
                foundTarget = checkflagTargetsMatch.Groups[1].Value;
            }

            return foundTarget;
        }
 public static bool cursorIsOnTextOfStyle(Place place, Style style, FastColoredTextBox editor)
 {
     return editor.GetStylesOfChar(place).Contains(style);
 }
Exemplo n.º 25
0
 public ToolTipNeededEventArgs(Place place, string hoveredWord)
 {
     HoveredWord = hoveredWord;
     Place       = place;
 }
Exemplo n.º 26
0
        /// <summary>
        /// Check if the given place in the editor is in a hyperlink
        /// </summary>
        /// <param name="place"></param>
        /// <returns></returns>
        bool CharIsHyperlink(Place place)
        {
            var mask = editor.GetStyleIndexMask(new Style[] { linkStyle });
            if (place.iChar < editor.GetLineLength(place.iLine))
            {
                if ((editor[place].style & mask) != 0)
                {
                    return true;
                }
            }

            return false;
        }
Exemplo n.º 27
0
        private Place NextPlace(Place p)
        {
            int lineLength = tb.GetLineLength(p.iLine);
            if (p.iChar < lineLength - 1)
            {
                return new Place(p.iChar+1, p.iLine);
            }
            else
            {
                // place is at last character of the line
                if (p.iLine < tb.LinesCount - 1)
                {
                    // move to next line
                    return new Place(0, p.iLine + 1);
                }
                else
                {
                    // already at last line, move to first line
                    return new Place(0,0);
                }

            }
        }
Exemplo n.º 28
0
        private string findGotoClickTarget(Place p)
        {
            MatchCollection matches = Matches(this.editor.GetLineText(p.iLine), @"(?i)(?<=(\@goto\(|then\(|chance[0-9]{2}\())[A-z_0-9öäüáéíóú+\s]+(?=\))"); //extracting the goto specifier

            string gotoName = null;
            for (int i = matches.Count - 1; i >= 0 && gotoName == null; i--)
            {
                if (matches[i].Groups[1].Index <= p.iChar)
                {
                    gotoName = matches[i].Groups[0].Value;
                }
            }

            return gotoName;
        }
Exemplo n.º 29
0
 private Place PrevPlace(Place p)
 {
     if (p.iChar == 0)
     {
         // move to previous line
         if (p.iLine == 0)
         {
             // already at first line, move to the last character at last line
             return new Place(tb.GetLineLength(tb.LinesCount - 1), tb.LinesCount - 1);
         }
         else
         {
             return new Place(tb.GetLineLength(p.iLine - 1) - 1, p.iLine - 1);
         }
     }
     else
     {
         return new Place(p.iChar - 1, p.iLine);
     }
 }
Exemplo n.º 30
0
        private string findVocabClickedTarget(Place p)
        {
            MatchCollection vocabClickedTargetsMatches = Matches(this.editor.GetLineText(p.iLine), @"(?i)(?<=\s|^)#[\w\-.]+(?=\s|$)"); //extracting the vocab name

            string foundTarget = null;
            
            for (int i = vocabClickedTargetsMatches.Count - 1; i >= 0 && foundTarget == null; i--)
            {
                if (vocabClickedTargetsMatches[i].Index <= p.iChar)
                {
                    foundTarget = vocabClickedTargetsMatches[i].Value;
                }
            }

            return foundTarget;
        }
Exemplo n.º 31
0
 private Place StartOfLine(Place p)
 {
     return new Place(0, p.iLine);
 }
Exemplo n.º 32
0
 private static void DropFromTheOutside(FastColoredTextBox textbox, Place place, string text)
 {
     textbox.Selection.BeginUpdate();
     // Insert text
     textbox.Selection.Start = place;
     textbox.InsertText(text);
     // Select inserted text
     textbox.Selection = new Range(textbox, place, textbox.Selection.Start);
     textbox.Selection.EndUpdate();
 }
Exemplo n.º 33
0
 private bool TryFindNext(string pattern, RegexOptions opt, FindNextDirection direction, Range range, out Place foundMatchPlace)
 {
     if (direction == FindNextDirection.Next)
     {
         foreach (var r in range.GetRangesByLines(pattern, opt))
         {
             foundMatchPlace = r.Start;
             tb.Selection = r;
             tb.DoSelectionVisible();
             tb.Invalidate();
             return true; // always return on the first match
         }
     }
     else // find previous
     {
         foreach (var r in range.GetRangesByLinesReversed(pattern, opt))
         {
             foundMatchPlace = r.Start;
             tb.Selection = r;
             tb.DoSelectionVisible();
             tb.Invalidate();
             return true; // always return on the first match
         }
     }
     foundMatchPlace = Place.Empty;
     return false;
 }
Exemplo n.º 34
0
 public RangeInfo(Range r)
 {
     Start = r.Start;
     End = r.End;
 }
Exemplo n.º 35
0
 private Place EndOfLine(Place p)
 {
     return new Place(tb.GetLineLength(p.iLine) - 1, p.iLine);
 }