Пример #1
0
        internal override void Execute(EmacsCommandContext context)
        {
            SnapshotSpan?previousWord = context.TextStructureNavigator.GetPreviousWord(context.TextView);

            if (!previousWord.HasValue ||
                !previousWord.Value.IntersectsWith(new Span(context.TextView.GetCaretPosition(), 1)))
            {
                return;
            }
            SnapshotSpan?nextWord = context.TextStructureNavigator.GetNextWord(previousWord.Value.End);

            if (!nextWord.HasValue)
            {
                return;
            }
            string text1 = context.TextView.TextSnapshot.GetText(previousWord.Value);
            string text2 = context.TextView.TextSnapshot.GetText(nextWord.Value);

            using (ITextEdit edit = context.TextView.TextBuffer.CreateEdit())
            {
                edit.Replace(nextWord.Value, text1);
                edit.Replace(previousWord.Value, text2);
                edit.Apply();
            }
            context.TextView.Caret.MoveTo(new SnapshotPoint(context.TextView.TextSnapshot, nextWord.Value.End));
            context.TextView.Caret.EnsureVisible();
        }
Пример #2
0
 internal override void Execute(EmacsCommandContext context)
 {
     try
     {
         changes = new StringBuilder();
         context.TextBuffer.Changed += OnTextBufferChanged;
         var nullable = new SnapshotSpan?();
         for (int argumentOrDefault = context.Manager.GetUniversalArgumentOrDefault(1);
              argumentOrDefault > 0;
              --argumentOrDefault)
         {
             nullable = !nullable.HasValue
                 ? context.TextStructureNavigator.GetNextWord(context.TextView)
                 : context.TextStructureNavigator.GetNextWord(nullable.Value.End);
         }
         if (nullable.HasValue)
         {
             SnapshotPoint caretPosition = context.TextView.GetCaretPosition();
             context.EditorOperations.Delete(caretPosition, nullable.Value.End - caretPosition);
         }
         KillwordClipboardSession clipboardSession =
             context.Manager.GetOrCreateKillClipboardSession(context.TextView);
         clipboardSession.KillwordSession = clipboardSession.KillwordSession + changes;
         context.Clipboard.Clear();
         context.Clipboard.Append(clipboardSession.KillwordSession);
     }
     finally
     {
         context.TextBuffer.Changed -= OnTextBufferChanged;
     }
 }
Пример #3
0
 internal override void ExecuteInverse(EmacsCommandContext context)
 {
     if (context.TextView.GetCaretPosition().Position >= context.TextBuffer.CurrentSnapshot.Length)
     {
         return;
     }
     context.EditorOperations.Delete();
 }
Пример #4
0
        internal override void Execute(EmacsCommandContext context)
        {
            SnapshotSpan?previousWord = context.TextStructureNavigator.GetPreviousWord(context.TextView);

            if (!previousWord.HasValue)
            {
                return;
            }
            context.EditorOperations.MoveCaret(previousWord.Value.Start);
        }
Пример #5
0
        internal override void ExecuteInverse(EmacsCommandContext context)
        {
            int num = Math.Abs(context.Manager.GetUniversalArgumentOrDefault(1));

            context.EditorOperations.ScrollLineBottom();
            for (int index = 0; index < num; ++index)
            {
                context.EditorOperations.ScrollDownAndMoveCaretIfNecessary();
            }
        }
Пример #6
0
        internal override void Execute(EmacsCommandContext context)
        {
            SnapshotSpan?nextWord = context.TextStructureNavigator.GetNextWord(context.TextView);

            if (!nextWord.HasValue)
            {
                return;
            }
            context.EditorOperations.MoveCaret(nextWord.Value.End);
        }
Пример #7
0
 internal override void Execute(EmacsCommandContext context)
 {
     if (!context.TextView.Selection.IsEmpty)
     {
         context.Clipboard.Append(context.EditorOperations.SelectedText);
     }
     else
     {
         context.Manager.UpdateStatus("The region is not active", false);
     }
 }
Пример #8
0
 internal override void Execute(EmacsCommandContext context)
 {
     if (!context.TextView.Selection.IsEmpty)
     {
         context.EditorOperations.CutSelection();
     }
     else
     {
         context.Manager.UpdateStatus(Resources.OperationCannotBePerformedWithoutTextSelection, false);
     }
 }
Пример #9
0
        internal override void Execute(EmacsCommandContext context)
        {
            IVsRunningDocumentTable service =
                context.Manager.ServiceProvider.GetService <SVsRunningDocumentTable, IVsRunningDocumentTable>();

            if (service == null)
            {
                return;
            }
            service.SaveDocuments(1U, null, 4294967294U, 0U);
        }
Пример #10
0
 internal override void Execute(EmacsCommandContext context)
 {
     if (context.Manager.ClipboardRing.Count <= 0)
     {
         return;
     }
     context.MarkSession.PushMark(true);
     LastPastedSpan = new Span(context.TextView.Caret.Position.BufferPosition.Position,
                               context.Manager.ClipboardRing.Last().Length);
     context.EditorOperations.InsertText(context.Manager.ClipboardRing.Last());
     context.Manager.ClipboardRingIndex = context.Manager.ClipboardRing.Count - 1;
     context.Manager.GetOrCreateKillClipboardSession(context.TextView).KillwordSession = string.Empty;
 }
Пример #11
0
        internal override void Execute(EmacsCommandContext context)
        {
            IVsUIShell service = context.Manager.ServiceProvider.GetService <SVsUIShell, IVsUIShell>();

            if (service == null)
            {
                return;
            }
            Guid   guid  = typeof(VSConstants.VSStd97CmdID).GUID;
            object pvaIn = 0;

            service.PostExecCommand(ref guid, 429U, 0U, ref pvaIn);
        }
Пример #12
0
        internal override void Execute(EmacsCommandContext context)
        {
            SnapshotSpan?nextWord = context.TextStructureNavigator.GetNextWord(context.TextView);

            if (!nextWord.HasValue)
            {
                return;
            }
            SnapshotPoint caretPosition = context.TextView.GetCaretPosition();
            var           span          = new Span(caretPosition, nextWord.Value.End - caretPosition);
            string        text          = context.TextView.TextSnapshot.GetText(span);

            context.TextBuffer.Replace(span, TransformText(text));
        }
Пример #13
0
        internal override void Execute(EmacsCommandContext context)
        {
            try
            {
                KillwordClipboardSession clipboardSession =
                    context.Manager.GetOrCreateKillClipboardSession(context.TextView);
                changes = new StringBuilder();
                context.TextBuffer.Changed += OnTextBufferChanged;
                int?universalArgument1 = context.Manager.UniversalArgument;
                if ((universalArgument1.GetValueOrDefault() != 0 ? 0 : (universalArgument1.HasValue ? 1 : 0)) != 0)
                {
                    context.EditorOperations.DeleteToBeginningOfPhysicalLine();
                    clipboardSession.KillwordSession = changes + clipboardSession.KillwordSession;
                }
                else
                {
                    if (context.UniversalArgument.HasValue)
                    {
                        int?universalArgument2 = context.UniversalArgument;
                        if ((universalArgument2.GetValueOrDefault() <= 0 ? 0 : (universalArgument2.HasValue ? 1 : 0)) ==
                            0)
                        {
                            goto label_11;
                        }
                    }
                    for (int argumentOrDefault = context.Manager.GetUniversalArgumentOrDefault(1);
                         argumentOrDefault > 0 && context.TextView.Caret.ContainingTextViewLine != null;
                         --argumentOrDefault)
                    {
                        if (context.TextView.GetCaretPosition() ==
                            context.TextView.Caret.ContainingTextViewLine.End.Position)
                        {
                            context.EditorOperations.Delete();
                        }
                        else
                        {
                            context.EditorOperations.DeleteToEndOfPhysicalLine();
                        }
                    }
                    clipboardSession.KillwordSession = clipboardSession.KillwordSession + changes;
                }
label_11:
                context.Clipboard.Clear();
                context.Clipboard.Append(clipboardSession.KillwordSession);
            }
            finally
            {
                context.TextBuffer.Changed -= OnTextBufferChanged;
            }
        }
Пример #14
0
        internal override void ExecuteInverse(EmacsCommandContext context)
        {
            SnapshotSpan?previousWord = context.TextStructureNavigator.GetPreviousWord(context.TextView);

            if (!previousWord.HasValue)
            {
                return;
            }
            SnapshotPoint caretPosition = context.TextView.GetCaretPosition();
            var           span          = new Span(previousWord.Value.Start, caretPosition - previousWord.Value.Start);
            string        text          = context.TextView.TextSnapshot.GetText(span);

            context.TextBuffer.Replace(span, TransformText(text));
            context.EditorOperations.MoveCaret(span.Start);
        }
Пример #15
0
 internal override void Execute(EmacsCommandContext context)
 {
     if (context.Manager.UniversalArgument.HasValue)
     {
         int num = context.Manager.UniversalArgument.Value;
         context.EditorOperations.ScrollLineTop();
         for (int index = 0; index < num; ++index)
         {
             context.EditorOperations.ScrollUpAndMoveCaretIfNecessary();
         }
     }
     else
     {
         context.EditorOperations.ScrollLineCenter();
     }
 }
Пример #16
0
        internal override void Execute(EmacsCommandContext context)
        {
            var service = context.Manager.ServiceProvider.GetService <DTE>();

            if (service.ActiveDocument == null || service.ActiveDocument.ActiveWindow == null)
            {
                return;
            }
            var textWindow = service.ActiveDocument.ActiveWindow.Object as TextWindow;

            if (textWindow == null || textWindow.Panes.Count != 2)
            {
                return;
            }
            context.CommandRouter.ExecuteDTECommand("Window.Split");
        }
Пример #17
0
 private bool CheckLastInvokedCommand(EmacsCommandContext context)
 {
     if (context.Manager.LastExecutedCommand != null)
     {
         if (context.Manager.LastExecutedCommand.Command == 26 &&
             new Guid(context.Manager.LastExecutedCommand.CommandGroup) == typeof(VSConstants.VSStd97CmdID).GUID)
         {
             LastPastedSpan = PasteCommand.LastPastedSpan;
             return(true);
         }
         if (context.Manager.LastExecutedCommand.Command == 37 &&
             new Guid(context.Manager.LastExecutedCommand.CommandGroup) == typeof(EmacsCommandID).GUID)
         {
             return(true);
         }
     }
     return(false);
 }
Пример #18
0
        internal override void Execute(EmacsCommandContext context)
        {
            SnapshotSpan?nextWord = context.TextStructureNavigator.GetNextWord(context.TextView);

            if (!nextWord.HasValue)
            {
                return;
            }
            if (context.TextView.GetCaretPosition().Position < nextWord.Value.Start)
            {
                context.EditorOperations.MoveCaret(nextWord.Value.Start);
            }
            context.EditorOperations.MakeUppercase();
            for (int position = context.TextView.GetCaretPosition().Position;
                 position < (int)nextWord.Value.End;
                 ++position)
            {
                context.EditorOperations.MakeLowercase();
            }
        }
Пример #19
0
        internal override void Execute(EmacsCommandContext context)
        {
            if (!CheckLastInvokedCommand(context))
            {
                throw new NoOperationException();
            }
            --context.Manager.ClipboardRingIndex;
            if (context.Manager.ClipboardRingIndex < 0)
            {
                context.Manager.ClipboardRingIndex = context.Manager.ClipboardRing.Count - 1;
            }
            if (context.Manager.ClipboardRingIndex == -1)
            {
                return;
            }
            string text = context.Manager.ClipboardRing[context.Manager.ClipboardRingIndex];

            context.EditorOperations.ReplaceText(LastPastedSpan, text);
            LastPastedSpan = new Span(LastPastedSpan.Start, text.Length);
            context.TextView.Selection.Select(new SnapshotSpan(context.TextView.TextSnapshot, LastPastedSpan), false);
        }
Пример #20
0
        internal override void Execute(EmacsCommandContext context)
        {
            int position = context.TextView.GetCaretPosition().Position;

            if (position <= 0)
            {
                return;
            }
            if (context.TextBuffer.CurrentSnapshot.GetText(context.TextView.GetCaretPosition() - 1, 1) == "\t")
            {
                context.TextView.Selection.Select(
                    new SnapshotSpan(context.TextView.TextSnapshot, new Span(position - 1, 1)), false);
                context.EditorOperations.ConvertTabsToSpaces();
                context.MarkSession.Deactivate(true);
                context.EditorOperations.Backspace();
            }
            else
            {
                context.EditorOperations.Backspace();
            }
        }
Пример #21
0
        internal override void Execute(EmacsCommandContext context)
        {
            int?universalArgument1 = context.UniversalArgument;

            if ((universalArgument1.GetValueOrDefault() != 4 ? 0 : (universalArgument1.HasValue ? 1 : 0)) != 0)
            {
                context.MarkSession.PopMark();
            }
            else
            {
                int?universalArgument2 = context.UniversalArgument;
                if ((universalArgument2.GetValueOrDefault() != 16 ? 0 : (universalArgument2.HasValue ? 1 : 0)) != 0)
                {
                    context.MarkSession.RemoveTopMark();
                }
                else
                {
                    context.MarkSession.PushMark(true);
                }
            }
        }
Пример #22
0
        internal override void ExecuteInverse(EmacsCommandContext context)
        {
            SnapshotSpan?previousWord = context.TextStructureNavigator.GetPreviousWord(context.TextView);

            if (!previousWord.HasValue)
            {
                return;
            }
            if (context.TextView.GetCaretPosition().Position > previousWord.Value.End)
            {
                context.EditorOperations.MoveCaret(previousWord.Value.End);
            }
            int position1 = previousWord.Value.Start.Position;

            for (int position2 = context.TextView.GetCaretPosition().Position - 1; position2 > position1; --position2)
            {
                context.EditorOperations.MoveCaret(position2);
                context.EditorOperations.MakeLowercase();
            }
            context.EditorOperations.MoveCaret(position1);
            context.EditorOperations.MakeUppercase();
            context.EditorOperations.MoveCaret(position1);
        }
Пример #23
0
 internal override void Execute(EmacsCommandContext context)
 {
     context.EditorOperations.InsertText(Environment.NewLine);
     context.EditorOperations.MoveToPreviousCharacter();
 }
Пример #24
0
 internal override void Execute(EmacsCommandContext context)
 {
     context.MarkSession.PopMark();
 }
Пример #25
0
 internal virtual void ExecuteInverse(EmacsCommandContext context)
 {
     throw new NotImplementedException();
 }
Пример #26
0
 internal abstract void Execute(EmacsCommandContext context);
Пример #27
0
 internal override void Execute(EmacsCommandContext context)
 {
     context.EditorOperations.Delete();
 }
Пример #28
0
 internal override void ExecuteInverse(EmacsCommandContext context)
 {
     context.EditorOperations.Backspace();
 }
Пример #29
0
        internal override void Execute(EmacsCommandContext context)
        {
            ITextSelection selection = context.TextView.Selection;
            bool           flag      = true;
            bool           isActive  = context.MarkSession.IsActive;

            if (context.TextBuffer.IsReadOnly(selection.Start.Position.GetContainingLine().Extent))
            {
                return;
            }
            if (!selection.IsEmpty)
            {
                if (selection.Mode == TextSelectionMode.Box)
                {
                    return;
                }
                VirtualSnapshotSpan streamSelectionSpan = selection.StreamSelectionSpan;
                if (streamSelectionSpan.Start.Position.GetContainingLine().LineNumber !=
                    streamSelectionSpan.End.Position.GetContainingLine().LineNumber)
                {
                    return;
                }
                selection.Clear();
                flag = false;
            }
            StripWhiteSpace(context.TextView.GetCaretPosition().GetContainingLine());
            int?desiredIndentation = context.Manager.SmartIndentationService.GetDesiredIndentation(context.TextView,
                                                                                                   context.TextView.GetCaretPosition().GetContainingLine());

            if (desiredIndentation.HasValue)
            {
                context.TextBuffer.Insert(context.TextView.GetCaretPosition().GetContainingLine().Start,
                                          new string(' ', desiredIndentation.Value));
                if (!context.TextView.Options.IsConvertTabsToSpacesEnabled())
                {
                    context.EditorOperations.ConvertSpacesToTabs();
                }
            }
            else
            {
                int num = 0;
                if (flag)
                {
                    CaretPosition position = context.TextView.Caret.Position;
                    context.EditorOperations.MoveToStartOfLineAfterWhiteSpace(false);
                    num = position.BufferPosition.Position - context.TextView.GetCaretPosition();
                }
                context.EditorOperations.SelectAndMoveCaret(
                    new VirtualSnapshotPoint(context.TextView.GetCaretPosition().GetContainingLine().Start, 0),
                    new VirtualSnapshotPoint(context.TextView.GetCaretPosition().GetContainingLine().End, 0));
                context.CommandRouter.ExecuteDTECommand("Edit.FormatSelection");
                context.EditorOperations.MoveToStartOfLineAfterWhiteSpace(false);
                if (num > 0)
                {
                    context.EditorOperations.MoveCaret(context.TextView.Caret.Position.BufferPosition + num, false);
                }
            }
            if (isActive)
            {
                return;
            }
            context.MarkSession.Deactivate(true);
        }