Пример #1
0
        public static Dictionary <int, EditorCursorCoordinate> GetCoordinates(HTMLTextAreaElement element, Author[] authors)
        {
            var value = element.Value + "_";

            div?.Remove();

            div = Document.CreateElement("div");
            Document.Body.AppendChild(div);

            var style    = div.Style;
            var computed = Window.GetComputedStyle(element);

            style.WhiteSpace = WhiteSpace.PreWrap;
            style.WordWrap   = "break-word";
            style.Position   = Position.Absolute;
            //style.Visibility = Visibility.Hidden;

            foreach (var prop in propeties)
            {
                style[prop] = computed[prop];
            }


            var positions = authors.Select(a => a.Position)
                            .Where(p => p < value.Length)
                            .Concat(new[] { value.Length, value.Length + 1 })
                            .OrderBy()
                            .Distinct()
                            .ToArray();

            div.TextContent = value.Substring(0, positions[0]);

            var result = new Dictionary <int, EditorCursorCoordinate>();
            var j      = 0;

            for (var i = 0; i < positions.Length - 1; i++)
            {
                var span = Document.CreateElement("span");
                span.Style.BackgroundColor = colors[j++ % colors.Length];
                span.TextContent           = value.Substring(positions[i], positions[i + 1]);

                div.AppendChild(span);
                result[positions[i]] = new EditorCursorCoordinate
                {
                    Top    = span.OffsetTop + SafeIntParse(computed.BorderTopWidth),
                    Left   = span.OffsetLeft + SafeIntParse(computed.BorderLeftWidth),
                    Height = SafeIntParse(computed.LineHeight)
                };
            }

            div.Remove();
            div = null;
            return(result);
        }
Пример #2
0
 public void Change(EditorCursorCoordinate coordinate)
 {
     this.coordinate = coordinate;
     Render();
 }