private void TabSelection(bool isShiftDown)
        {
            ITextSelection selection = CodeEditor.Document.Selection;

            ITextRange range          = selection.GetClone();
            int        selectionStart = range.StartPosition;

            range.StartOf(TextRangeUnit.Line, false);
            int lineStart = range.StartPosition;

            int charactersFromLineStart     = selectionStart - lineStart;
            int charactersOffsetFromTabSize = charactersFromLineStart % ViewModel.TabSize;

            if (isShiftDown)
            {
                int        charactersToDelete = charactersOffsetFromTabSize == 0 ? ViewModel.TabSize : charactersOffsetFromTabSize;
                ITextRange deletionRange      = selection.GetClone();

                if (deletionRange.StartPosition > lineStart)
                {
                    deletionRange.MoveStart(TextRangeUnit.Character, -1);

                    int safeCharactersToDelete;

                    for (safeCharactersToDelete = 0; safeCharactersToDelete < charactersToDelete && deletionRange.StartPosition >= lineStart && char.IsWhiteSpace(deletionRange.Character); safeCharactersToDelete++)
                    {
                        deletionRange.MoveStart(TextRangeUnit.Character, -1);
                    }

                    CodeEditor.Document.GetRange(selection.StartPosition, selection.StartPosition).Delete(TextRangeUnit.Character, -safeCharactersToDelete);
                }
            }
            else
            {
                int    charactersToAdd = ViewModel.TabSize - charactersOffsetFromTabSize;
                string tabString       = new string(' ', charactersToAdd);

                selection.TypeText(tabString);
            }
        }
예제 #2
0
        private void HandleTap(TappedRoutedEventArgs e)
        {
            Point      tappedPoint = e.GetPosition(this);
            ITextRange textRange   = this.Document.GetRangeFromPoint(tappedPoint, PointOptions.ClientCoordinates);

            textRange.StartOf(TextRangeUnit.Link, true);

            if (textRange.Character != '\r' && textRange.CharacterFormat.Underline == UnderlineType.Single)
            {
                string content;
                this.Document.GetText(TextGetOptions.None, out content);

                textRange.StartPosition--;
                textRange.EndPosition++;
                while (!(textRange.Text.StartsWith(" ") || textRange.Text.StartsWith("\r")) && textRange.StartPosition > 0)
                {
                    textRange.StartPosition--;
                }
                while (!(textRange.Text.EndsWith(" ") || textRange.Text.EndsWith("\r")) && textRange.EndPosition < content.Length)
                {
                    textRange.EndPosition++;
                }

                this.link = textRange.Text;
                if (!string.IsNullOrWhiteSpace(this.link))
                {
                    this.link = this.link.Trim(' ');
                    this.link = this.link.Trim('\r');

                    if (!this.link.StartsWith("http://", StringComparison.OrdinalIgnoreCase) && !this.link.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
                    {
                        this.link = "http://" + this.link;
                    }

                    if (this.openLinkPopup == null)
                    {
                        this.openLinkPopup = new Popup
                        {
                            IsLightDismissEnabled = true,
                            Child = new HyperlinkPopupContent()
                        };
                    }

                    this.openLinkPopup.IsOpen = false;
                    ((HyperlinkPopupContent)this.openLinkPopup.Child).Hyperlink = this.link;
                    var frame = Window.Current.Content as Frame;
                    if (frame != null && frame.Content is Page)
                    {
                        var page = frame.Content as Page;

                        var position = e.GetPosition(page);
                        this.openLinkPopup.VerticalOffset = position.Y;

                        if (ResponsiveHelper.IsUsingSmallLayout())
                        {
                            this.openLinkPopup.HorizontalOffset = 15;
                            ((HyperlinkPopupContent)this.openLinkPopup.Child).MaxWidth = 292;
                        }
                        else
                        {
                            this.openLinkPopup.HorizontalOffset = position.X;
                        }
                    }

                    this.openLinkPopup.IsOpen = true;
                }
            }
        }