Beispiel #1
0
        public void RunCommand_ExpandsCssAbbreviation()
        {
            // Arrange
            string       result = string.Empty;
            IEmmetEditor editor = Substitute.For <IEmmetEditor>();

            editor.GetContentTypeInActiveBuffer().Returns("css");
            editor.GetContent().Returns("p10");
            editor.GetSelectionRange().Returns(new Range(3, 3));
            editor.GetCurrentLineRange().Returns(new Range(0, 3));
            editor.GetCaretPosition().Returns(3);
            editor.ReplaceContentRange(Arg.Do <string>(s => result = s), Arg.Any <int>(), Arg.Any <int>());

            // Act
            _engine.RunCommand(PackageIds.CmdIDExpandAbbreviation, editor).Should().BeTrue();
            result.Should().Be("padding: 10px;");
        }
        /// <summary>
        /// JavaScript callback. Replace editor's content or it's part (from <code>start</code> to
        /// <code>end</code> index). If <code>value</code> contains <code>caret_placeholder</code>, the editor
        /// will put caret into this position. If you skip <code>start</code> and <code>end</code> arguments,
        /// the whole target's content will be replaced with <code>value</code>.
        /// If you pass <code>start</code> argument only, the <code>value</code> will be placed at
        /// <code>start</code> string index of current content.
        /// If you pass <code>start</code> and <code>end</code> arguments, the corresponding substring of
        /// current target's content will be replaced with <code>value</code>.
        /// </summary>
        public InternalHandle ReplaceContent(
            V8Engine engine,
            bool isConstructCall,
            InternalHandle self,
            params InternalHandle[] args)
        {
            string rawContent    = args[0].AsString;
            int    regionStart   = args.Length > 1 ? args[1].AsInt32 : -1;
            int    regionLength  = args.Length > 2 ? args[2].AsInt32 - regionStart : 0;
            bool   indentContent = args.Length == 4 ? args[3].AsBoolean : true;

            this.Trace($"Received new content for the editor: {rawContent}");

            // Extract tab stops placeholders from the specified content.
            var tabStops = TabStopsParser.ParseContent(engine, rawContent);

            _editor.ReplaceContentRange(tabStops.Content, regionStart, regionStart + regionLength);

            if (null != tabStops.TabStops)
            {
                Range[] tabStopRanges = tabStops.TabStops;

                // Tab stop offsets are relative to the newly generated content ranges, we need to convert
                // them to the document-wide offsets.
                if (regionStart > 0)
                {
                    tabStopRanges = tabStopRanges.Select(
                        item => new Range(item.Start + regionStart, item.End + regionStart)).ToArray();
                }

                _editor.TrackTabStops(tabStopRanges, tabStops.TabStopGroups);
            }

            if (indentContent)
            {
                _editor.FormatRegion(regionStart, regionStart + tabStops.Content.Length);
            }

            return(engine.CreateValue(true));
        }