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 InvokeTokenSelected(ITextSelection selection)
        {
            if (TokenSelected == null || !TryGetTokenFromRange(selection, out var token) || token.RangeEnd != selection.EndPosition)
            {
                return;
            }

            TokenSelected.Invoke(this, new RichSuggestTokenSelectedEventArgs
            {
                Token = token,
                Range = selection.GetClone()
            });
        }