Exemplo n.º 1
0
        private void Brainf_ckEditBox_SelectionChanged(object sender, RoutedEventArgs e)
        {
            ScrollToSelection(out Rect rect);

            // Adjust the UI of the selected line highlight and the cursor indicator.
            // Both elements are translated to the right position and made visible
            // if the current selection is not collapsed to a single point, otherwise
            // they're both hidden. This is the same behavior of Visual Studio.
            if (_SelectionLength > 0)
            {
                _SelectionHighlightBorder !.Opacity    = 0;
                _CursorIndicatorRectangle !.Visibility = Visibility.Collapsed;
            }
            else
            {
                // Line highlight
                _SelectionHighlightBorder !.Opacity = 1;
                ((TranslateTransform)_SelectionHighlightBorder.RenderTransform).Y = rect.Top + Padding.Top;

                // Cursor indicator
                _CursorIndicatorRectangle !.Visibility = Visibility.Visible;
                TranslateTransform cursorTransform = (TranslateTransform)_CursorIndicatorRectangle.RenderTransform;
                cursorTransform.X = rect.X + Padding.Left;
                cursorTransform.Y = rect.Y + Padding.Top;
            }

            var position = Text.CalculateCoordinates(Document.Selection.EndPosition);
            var args     = new CursorPositionChangedEventArgs(position.Row + 1, position.Column + 1);

            // Signal the cursor movement
            CursorPositionChanged?.Invoke(this, args);
        }
 /// <summary>
 /// Raises the <see cref="CursorPositionChanged"/> event
 /// </summary>
 /// <param name="sender">The <see cref="Brainf_ckEditBox"/> instance in use</param>
 /// <param name="args">The arguments for the cursor movement</param>
 private void CodeEditBox_CursorPositionChanged(Brainf_ckEditBox sender, CursorPositionChangedEventArgs args)
 {
     CursorPositionChanged?.Invoke(this, args);
 }