void ExpressionTextBox_PostPaint(ColorizedPlainTextBox sender, Graphics g)
        {
            Size client_size = m_ExpressionTextBox.ClientSize;

            if (client_size.IsEmpty)
            {
                return;
            }
            int start_char_index = m_ExpressionTextBox.GetCharIndexFromPosition(new Point(0, 0));
            int last_visible_line_start_char_index = m_ExpressionTextBox.GetCharIndexFromPosition(new Point(0, client_size.Height - 1));
            int last_visible_line = m_ExpressionTextBox.GetLineFromCharIndex(last_visible_line_start_char_index);
            int end_char_index;

            if (last_visible_line + 1 >= m_ExpressionTextBox.LineCount)
            {
                end_char_index = m_ExpressionTextBox.TextLength;
            }
            else
            {
                end_char_index = m_ExpressionTextBox.GetLineStartCharIndexFromLineNumber(last_visible_line + 1);
            }
            Debug.Assert(start_char_index <= end_char_index);
            if (start_char_index > end_char_index)
            {
                return;
            }

            List <UnderlineDataContainer.Underline> underlines = UnderlineData.Underlines;
            int start_idx = underlines.BinarySearch(new UnderlineDataContainer.Underline(start_char_index, start_char_index), UnderlineBeginComparer.Instance);
            int end_idx   = underlines.BinarySearch(new UnderlineDataContainer.Underline(end_char_index, end_char_index), UnderlineBeginComparer.Instance);

            if (start_idx < 0)
            {
                start_idx = ~start_idx;
            }
            if (end_idx < 0)
            {
                end_idx = ~end_idx;
            }

            int y_offset = m_ExpressionTextBox.Font.Height - 1;

            for (int i = start_idx; i < end_idx; ++i)
            {
                UnderlineDataContainer.Underline underline = underlines[i];
                Point pos0 = m_ExpressionTextBox.GetPositionFromCharIndex(underline.Begin);
                Point pos1 = m_ExpressionTextBox.GetPositionFromCharIndex(underline.End);
                int   y    = pos0.Y + y_offset;
                DrawUnderline(y, pos0.X, pos1.X, g);
            }
        }
        public void CharIdxToLineAndColumn(int char_idx, out int line, out int column)
        {
            line = GetLineFromCharIndex(char_idx);
            // If the textbox isn't empty and the cursor is at the end of the whole text of
            // the textbox and the last line is empty then GetLineFromCharIndex() returns the
            // index of the previous line and we work around this by using LineCount-1
            // instead that seems to give the correct value.
            if (char_idx > 0 && char_idx >= TextLength)
            {
                line = LineCount - 1;
            }
            int    line_first_char_idx = Math.Max(0, GetFirstCharIndexFromLine(line));
            string line_text           = GetTextRange(line_first_char_idx, char_idx);

            column = ColorizedPlainTextBox.GetColumnIndexFromTabbedText(line_text, 0, line_text.Length, ExpressionTextBox.TAB_SIZE);
        }
Esempio n. 3
0
 void text_box_VerticalScrollPosChanged(ColorizedPlainTextBox sender)
 {
     DelayedUpdateLineNumbers();
 }
 void m_TextBox_UndoEntryAdded(ColorizedPlainTextBox.UndoEntry undo_entry)
 {
     HighlightRange(undo_entry.Pos, undo_entry.PastedText.Length);
 }
 void m_TextBox_AfterUndo(ColorizedPlainTextBox.UndoEntry undo_entry)
 {
     HighlightRange(undo_entry.Pos, undo_entry.CutText.Length);
 }