Beispiel #1
0
        private void HighlightVisibleText()
        {
            TryCleanCurrentFileHighlighting();
            if (_expectedWords.Count == 0)
            {
                return;
            }
            _lastHighlightTime = DateUtils.CurrentUts();
            var lastHighlightTime = _lastHighlightTime;

            var linesOnScreen   = _gateway.LinesOnScreen();
            var totalLinesCount = _gateway.GetLineCount();
            int lineIndex       = _startLineIndex - 1;


            while (linesOnScreen-- > 0)
            {
                // прерываем текущий процесс подсветки, потому что запустился новый
                if (IsNeedToBreak(lastHighlightTime))
                {
                    return;
                }

                lineIndex++;
                if (lineIndex >= totalLinesCount)
                {
                    return;
                }

                if (!_gateway.GetLineVisible(lineIndex))
                {
                    // перепрыгиваем hidden/collapsed lines
                    int invisibleNoDocLine = _gateway.VisibleFromDocLine(lineIndex);
                    lineIndex = _gateway.DocLineFromVisible(invisibleNoDocLine);
                }

                var           isEscape    = false;
                StringBuilder currentWord = null;
                var           lineText    = _gateway.GetLineText(lineIndex);

                for (int i = 0; i < lineText.Length; i++)
                {
                    var ch = lineText[i];

                    if (!isEscape && ch == '"')
                    {
                        if (currentWord == null)
                        {
                            currentWord = new StringBuilder();
                        }
                        else
                        {
                            string word       = currentWord.ToString();
                            var    wordLength = word.Length;
                            if (IsNeedToBreak(lastHighlightTime))
                            {
                                return;
                            }

                            if (IsNeedToHighlightWord(word, lineIndex, i - wordLength, lastHighlightTime))
                            {
                                // TODO может помочь победить баг с кириллицей
                                // int position = _gateway.LineToPosition(lineIndex) + i;
                                // int startPosition = _gateway.WordStartPosition(position, true);
                                // int endPosition = _gateway.WordEndPosition(position, true);
                                // HighlightWord(startPosition, endPosition - startPosition);

                                // в доке эта штука была описана как то, что мне нужно (
                                // int position = _gateway.IndexPositionFromLine(lineIndex, i - wordLength);

                                int position = _gateway.LineToPosition(lineIndex) + i - wordLength;
                                HighlightWord(position, wordLength);
                            }

                            currentWord = null;
                        }
                    }
                    else if (currentWord != null)
                    {
                        if (ch.IsPartOfWord())
                        {
                            currentWord.Append(ch);
                        }
                        else
                        {
                            currentWord = null;
                        }
                    }

                    isEscape = !isEscape && ch == '\\';
                }
            }
        }