示例#1
0
        public override int GetFirstInterestedOffset(int startOffset)
        {
            if (Lines == null)
            {
                return(startOffset);
            }

            var location = CurrentContext.Document.GetLocation(startOffset);

            var columnNumberWithOffset = _columnWidthCalculator.GetColumn(Lines, location);
            var locationLine           = location.Line;

            if (columnNumberWithOffset.ColumnNumber == ColumnWidth.Length - 1)
            {
                if (Lines.Length == locationLine)
                {
                    return(CurrentContext.VisualLine.LastDocumentLine.EndOffset);
                }
                else
                {
                    columnNumberWithOffset = new ColumnNumberWithOffset
                    {
                        ColumnNumber = 0,
                        OffsetInLine = Lines[locationLine][0]
                    };
                    locationLine++;
                }
            }

            _tabWidth = ColumnWidth[columnNumberWithOffset.ColumnNumber] -
                        Lines[locationLine - 1][columnNumberWithOffset.ColumnNumber];

            return(CurrentContext.Document.GetOffset(new TextLocation(locationLine, columnNumberWithOffset.OffsetInLine)));
        }
        private void OnDocumentChanging(object sender, DocumentChangeEventArgs e)
        {
            var affectedLocation = Document.GetLocation(e.Offset);

            var columnWidth       = _elementGenerator.ColumnWidth;
            var columnWidthByLine = _elementGenerator.Lines;

            var columnNumberWithOffset = _columnWidthCalculator.GetColumn(columnWidthByLine, affectedLocation);

            var myColumn = columnNumberWithOffset.ColumnNumber;
            var oldWidth = columnWidthByLine[affectedLocation.Line - 1][myColumn];
            var length   = e.InsertionLength - e.RemovalLength;

            columnWidthByLine[affectedLocation.Line - 1][myColumn] = oldWidth + length;

            if (length > 0)
            {
                if (oldWidth + length > columnWidth[myColumn])
                {
                    columnWidth[columnNumberWithOffset.ColumnNumber] = oldWidth + length;

                    UpdateLines();
                }
            }
            else
            {
                var maxLength = columnWidthByLine.Select(x => x[myColumn]).Max();

                if (maxLength != columnWidth[myColumn])
                {
                    columnWidth[myColumn] = maxLength;

                    UpdateLines();
                }
            }
        }