private bool Move(Direction direction)
        {
            if (!EnsureInitialized())
            {
                return(false);
            }

            int position = _textView.Caret.Position.BufferPosition.Position;

            ParseItem item = _tree.StyleSheet.ItemBeforePosition(position);

            if (item == null)
            {
                return(false);
            }

            NumericalValue unit = item.FindType <NumericalValue>();

            if (unit != null)
            {
                return(HandleUnits(direction, unit));
            }

            HexColorValue hex = item.FindType <HexColorValue>();

            if (hex != null)
            {
                return(HandleHex(direction, hex));
            }

            return(false);
        }
Exemple #2
0
        public IEnumerable <ISmartTagAction> GetSmartTagActions(ParseItem item, int position, ITrackingSpan itemTrackingSpan, ITextView view)
        {
            HexColorValue hex = (HexColorValue)item;

            if (!item.IsValid)
            {
                yield break;
            }

            ColorModel model = ColorParser.TryParseColor(hex.Text, ColorParser.Options.None);

            if (model != null)
            {
                if (ColorConverterSmartTagAction.GetNamedColor(model.Color) != null)
                {
                    yield return(new ColorConverterSmartTagAction(itemTrackingSpan, model, ColorFormat.Name));
                }

                if (model.Format == ColorFormat.RgbHex6)
                {
                    model.Format = ColorFormat.RgbHex3;
                    string hex3 = ColorFormatter.FormatColor(model, ColorFormat.RgbHex3);

                    if (hex3.Length == 4)
                    {
                        yield return(new ColorConverterSmartTagAction(itemTrackingSpan, model, ColorFormat.RgbHex3));
                    }
                }

                yield return(new ColorConverterSmartTagAction(itemTrackingSpan, model, ColorFormat.Rgb));

                yield return(new ColorConverterSmartTagAction(itemTrackingSpan, model, ColorFormat.Hsl));
            }
        }
Exemple #3
0
        public void HexColorValue_ParseTest2()
        {
            string        text   = "#0;";
            ITextProvider tp     = new StringTextProvider(text);
            TokenStream   tokens = Helpers.MakeTokenStream(tp);
            HexColorValue h      = new HexColorValue();

            Assert.IsTrue(h.Parse(new ItemFactory(tp, null), tp, tokens));
            bool isNumber = h.TryGetNumberRange(out int numberStart, out int numberLength);

            Assert.IsTrue(isNumber);
            Assert.AreEqual(1, numberStart);
            Assert.AreEqual(text.Length - 1, numberStart + numberLength);

            int n = int.Parse(text.Substring(numberStart, numberLength), NumberStyles.HexNumber);

            Assert.AreEqual(0, n);
        }
Exemple #4
0
        private bool Move(Direction direction)
        {
            if (WebEditor.Host == null)
            {
                return(false);
            }

            var point = _textView.BufferGraph.MapDownToInsertionPoint(_textView.Caret.Position.BufferPosition, PointTrackingMode.Positive, ts => ts.ContentType.IsOfType(CssContentTypeDefinition.CssContentType));

            if (point == null)
            {
                return(false);
            }

            var       tree = CssEditorDocument.FromTextBuffer(point.Value.Snapshot.TextBuffer);
            ParseItem item = tree.StyleSheet.ItemBeforePosition(point.Value.Position);

            if (item == null)
            {
                return(false);
            }

            NumericalValue unit = item.FindType <NumericalValue>();

            if (unit != null)
            {
                return(HandleUnits(direction, unit, point.Value.Snapshot));
            }

            HexColorValue hex = item.FindType <HexColorValue>();

            if (hex != null)
            {
                return(HandleHex(direction, hex, point.Value.Snapshot));
            }

            return(false);
        }
Exemple #5
0
        private static bool HandleHex(Direction direction, HexColorValue item, ITextSnapshot snapshot)
        {
            var model = ColorParser.TryParseColor(item.Text, ColorParser.Options.None);

            if (model != null)
            {
                var span = new SnapshotSpan(snapshot, item.Start, item.Length);

                if (direction == Direction.Down && model.HslLightness > 0)
                {
                    model.Format = Editor.ColorFormat.RgbHex3;
                    UpdateSpan(span, Editor.ColorFormatter.FormatColor(model.Darken(), model.Format), "Darken color");
                }
                else if (direction == Direction.Up && model.HslLightness < 1)
                {
                    model.Format = Editor.ColorFormat.RgbHex3;
                    UpdateSpan(span, Editor.ColorFormatter.FormatColor(model.Brighten(), model.Format), "Brighten color");
                }

                return(true);
            }

            return(false);
        }
        private static bool HandleHex(Direction direction, HexColorValue item, ITextSnapshot snapshot)
        {
            var model = ColorParser.TryParseColor(item.Text, ColorParser.Options.None);

            if (model != null)
            {
                var span = new SnapshotSpan(snapshot, item.Start, item.Length);

                if (direction == Direction.Down && model.HslLightness > 0)
                {
                    model.Format = Editor.ColorFormat.RgbHex3;
                    UpdateSpan(span, Editor.ColorFormatter.FormatColor(model.Darken(), model.Format), "Darken color");
                }
                else if (direction == Direction.Up && model.HslLightness < 1)
                {
                    model.Format = Editor.ColorFormat.RgbHex3;
                    UpdateSpan(span, Editor.ColorFormatter.FormatColor(model.Brighten(), model.Format), "Brighten color");
                }

                return true;
            }

            return false;
        }