public void Draw() { var lines = _textView.TextViewLines; var snapshot = _textView.TextSnapshot; var text = snapshot.GetText(); // TODO: move to options var regex = new Regex(@"[A-Z]+([0-9a-z]*)|[a-z0-9]{2,}", RegexOptions.Compiled); var matches = regex.Matches(text).OfType <Match>().ToArray(); var pairs = KeyboardLayoutHelper.EnumeratePairs().GetEnumerator(); foreach (var match in matches) { int position = match.Index; var span = new SnapshotSpan(snapshot, position, 1); Geometry charGeometry = lines.GetMarkerGeometry(span); if (charGeometry != null) { if (!pairs.MoveNext()) { return; } var pair = pairs.Current; var model = new JumpKeysViewModel { Position = position, Active = true, FirstKey = pair.Item1, SecondKey = pair.Item2, }; var control = new JumpKeysControl(model); // TODO: set line height and offset based on _textView.LineHeight int verticalOffset = 8; Canvas.SetLeft(control, charGeometry.Bounds.Left); Canvas.SetTop(control, charGeometry.Bounds.Top - verticalOffset); _jumpyLayer.AddAdornment(AdornmentPositioningBehavior.TextRelative, span, null, control, null); } } }
public void Draw() { var lines = _textView.TextViewLines; var snapshot = _textView.TextSnapshot; var text = snapshot.GetText(); // TODO: move to options var regex = new Regex(@"[A-Z]+([0-9a-z]*)|[a-z0-9]{2,}", RegexOptions.Compiled); var matches = regex.Matches(text).OfType<Match>().ToArray(); var pairs = KeyboardLayoutHelper.EnumeratePairs().GetEnumerator(); foreach (var match in matches) { int position = match.Index; var span = new SnapshotSpan(snapshot, position, 1); Geometry charGeometry = lines.GetMarkerGeometry(span); if (charGeometry != null) { if (!pairs.MoveNext()) return; var pair = pairs.Current; var model = new JumpKeysViewModel { Position = position, Active = true, FirstKey = pair.Item1, SecondKey = pair.Item2, }; var control = new JumpKeysControl(model); // TODO: set line height and offset based on _textView.LineHeight int verticalOffset = 8; Canvas.SetLeft(control, charGeometry.Bounds.Left); Canvas.SetTop(control, charGeometry.Bounds.Top - verticalOffset); _jumpyLayer.AddAdornment(AdornmentPositioningBehavior.TextRelative, span, null, control, null); } } }
public JumpKeysControl(JumpKeysViewModel model) { InitializeComponent(); Model = model; DataContext = model; }