Exemplo n.º 1
0
        /// <summary>
        /// Removes all tags associated with a given node
        /// </summary>
        /// <param name="node">Node in the AST</param>
        /// <returns>Text range that encloses removed tag spans</returns>
        public ITextRange RemoveTagsForNode(IAstNode node)
        {
            int        start = _editorTree.TextBuffer().CurrentSnapshot.Length;
            ITextRange range = TextRange.EmptyRange;
            int        end   = 0;

            lock (_lockObj) {
                // Remove all tags for this node
                for (int i = 0; i < _tags.Count; i++)
                {
                    if (TextRange.ContainsInclusiveEnd(node, _tags[i]))
                    {
                        start = Math.Min(start, _tags[i].Start);
                        end   = Math.Max(end, _tags[i].End);

                        RemovedTags.Enqueue(_tags[i]);

                        _tags.RemoveAt(i);
                        i--;

                        range = TextRange.Union(range, start, end - start);
                    }
                }
            }

            return(range);
        }
Exemplo n.º 2
0
        public void TextRangeCollection_RemoveAtTest()
        {
            TextRangeCollection <TextRange> target = MakeCollection();

            AssertEquals(target, 1, 2, 3, 5, 5, 7);

            target.RemoveAt(0);
            AssertEquals(target, 3, 5, 5, 7);

            target.RemoveAt(1);
            AssertEquals(target, 3, 5);

            target.RemoveAt(0);
            AssertEquals(target);
        }
Exemplo n.º 3
0
        protected override void RemoveSensitiveTokens(int position, TextRangeCollection <RToken> tokens)
        {
            if (tokens == null)
            {
                return;
            }

            bool foundSpace = false;

            while (tokens.Count > 0 && !foundSpace)
            {
                int count = tokens.Count;
                var token = tokens[count - 1];

                if ((token.TokenType == RTokenType.Number || token.TokenType == RTokenType.Complex) && token.End + 2 >= position)
                {
                    // This handles case when user types 1.23e1. In 1.23e case 'e' is not part
                    // of the number since 1.23e is not a valid js number. However, 1.23e+1 is
                    // a valid number. Hence we are considering typing within 2 character of
                    // a number token to be  a sensitive change.
                    tokens.RemoveAt(count - 1);
                    continue;
                }

                if (count > 1)
                {
                    if (token.Start != tokens[count - 2].End)
                    {
                        foundSpace = true;
                        break;
                    }

                    tokens.RemoveAt(count - 1);
                    continue;
                }

                break;
            }

            base.RemoveSensitiveTokens(position, tokens);
        }
Exemplo n.º 4
0
        protected override void RemoveSensitiveTokens(int position, TextRangeCollection <MarkdownToken> tokens)
        {
            // Check if change damages code block. Normally base classifier removes all tokens
            // from the caret position to the end of the visible area. If typing is inside
            // the code area it may also affects tokens starting from the beginning of the code
            // block. For example, when user types ``` in a middle of existing ```...``` block.
            // This is similar to typing %> or ?> in a middle of ASP.NET or PHP block.
            int last = tokens.Count - 1;

            if (last >= 0 && tokens[last].TokenType == MarkdownTokenType.Code)
            {
                tokens.RemoveAt(last);
            }

            base.RemoveSensitiveTokens(position, tokens);
        }