Пример #1
0
        internal override void Execute(EmacsCommandContext context)
        {
            if (context.Manager.UniversalArgument.HasValue)
            {
                var lineNumber = context.Manager.UniversalArgument.Value - 1;

                if (lineNumber < 0)
                {
                    context.EditorOperations.MoveToStartOfDocument();
                }
                else if (lineNumber >= context.TextView.TextSnapshot.LineCount)
                {
                    context.EditorOperations.MoveToEndOfDocument();
                }
                else
                {
                    context.EditorOperations.GotoLine(lineNumber);
                }
            }
            else
            {
                // Execute the built-in VS go-to command
                context.CommandRouter.ExecuteDTECommand(VsCommands.GoToCommandName);
            }
        }
 internal override void Execute(EmacsCommandContext context)
 {
     if (!context.TextView.Selection.IsEmpty)
         context.EditorOperations.Delete();
     else
         context.Manager.UpdateStatus(Resources.OperationCannotBePerformedWithoutTextSelection);
 }
Пример #3
0
        internal override void Execute(EmacsCommandContext context)
        {
            var previousWordSpan = context.TextStructureNavigator.GetPreviousWord(context.TextView);

            if (previousWordSpan.HasValue && previousWordSpan.Value.IntersectsWith(new Span(context.TextView.GetCaretPosition(), 1)))
            {
                var nextWordSpan = context.TextStructureNavigator.GetNextWord(previousWordSpan.Value.End);

                if (nextWordSpan.HasValue)
                {
                    var previousWord = context.TextView.TextSnapshot.GetText(previousWordSpan.Value);
                    var nextWord     = context.TextView.TextSnapshot.GetText(nextWordSpan.Value);

                    using (var edit = context.TextView.TextBuffer.CreateEdit())
                    {
                        edit.Replace(nextWordSpan.Value, previousWord);
                        edit.Replace(previousWordSpan.Value, nextWord);

                        edit.Apply();
                    }

                    context.TextView.Caret.MoveTo(new SnapshotPoint(context.TextView.TextSnapshot, nextWordSpan.Value.End));
                    context.TextView.Caret.EnsureVisible();
                }
            }
        }
Пример #4
0
        internal override void Execute(EmacsCommandContext context)
        {
            ITextSelection selection = context.TextView.Selection;
            ClipboardRing  ring      = context.Manager.ClipboardRing;

            if (!ring.IsEmpty)
            {
                ITrackingSpan preInsertionSelectionSpan = null;

                if (!selection.IsEmpty)
                {
                    // Currently only support stream selection
                    if (selection.Mode == TextSelectionMode.Stream)
                    {
                        preInsertionSelectionSpan = context.TextView.TextSnapshot.CreateTrackingSpan(selection.StreamSelectionSpan.SnapshotSpan, SpanTrackingMode.EdgeInclusive);
                    }
                    else
                    {
                        selection.Clear();
                    }
                }
                else
                {
                    preInsertionSelectionSpan = context.TextView.TextSnapshot.CreateTrackingSpan(new Span(selection.AnchorPoint.Position, 0), SpanTrackingMode.EdgeInclusive);
                }

                context.EditorOperations.ReplaceSelection(ring.GetNext());

                // Select newly inserted text
                SnapshotSpan newSelectionRange = preInsertionSelectionSpan.GetSpan(context.TextView.TextSnapshot);
                context.EditorOperations.SelectAndMoveCaret(new VirtualSnapshotPoint(newSelectionRange.Start), new VirtualSnapshotPoint(newSelectionRange.End));
            }
        }
Пример #5
0
        internal override void Execute(EmacsCommandContext context)
        {
            ITextSelection selection = context.TextView.Selection;
            ClipboardRing ring = context.Manager.ClipboardRing;

            if (!ring.IsEmpty)
            {
                ITrackingSpan preInsertionSelectionSpan = null;

                if (!selection.IsEmpty)
                {
                    // Currently only support stream selection
                    if (selection.Mode == TextSelectionMode.Stream)
                    {
                        preInsertionSelectionSpan = context.TextView.TextSnapshot.CreateTrackingSpan(selection.StreamSelectionSpan.SnapshotSpan, SpanTrackingMode.EdgeInclusive);
                    }
                    else
                    {
                        selection.Clear();
                    }
                }
                else
                {
                    preInsertionSelectionSpan = context.TextView.TextSnapshot.CreateTrackingSpan(new Span(selection.AnchorPoint.Position, 0), SpanTrackingMode.EdgeInclusive);
                }
                
                context.EditorOperations.ReplaceSelection(ring.GetNext());

                // Select newly inserted text
                SnapshotSpan newSelectionRange = preInsertionSelectionSpan.GetSpan(context.TextView.TextSnapshot);
                context.EditorOperations.SelectAndMoveCaret(new VirtualSnapshotPoint(newSelectionRange.Start), new VirtualSnapshotPoint(newSelectionRange.End));
            }
        }
Пример #6
0
        internal override void Execute(EmacsCommandContext context)
        {
            if (context.Manager.UniversalArgument.HasValue)
            {
                var lineNumber = context.Manager.UniversalArgument.Value - 1;

                if (lineNumber < 0)
                {
                    context.EditorOperations.MoveToStartOfDocument();
                }
                else if (lineNumber >= context.TextView.TextSnapshot.LineCount)
                {
                    context.EditorOperations.MoveToEndOfDocument();
                }
                else
                {
                    context.EditorOperations.GotoLine(lineNumber);
                }
            }
            else
            {
                // Execute the built-in VS go-to command
                context.CommandRouter.ExecuteDTECommand(VsCommands.GoToCommandName);
            }
        }
Пример #7
0
        internal override void Execute(EmacsCommandContext context)
        {
            var previousWordSpan = context.TextStructureNavigator.GetPreviousWord(context.TextView);

            if (previousWordSpan.HasValue && previousWordSpan.Value.IntersectsWith(new Span(context.TextView.GetCaretPosition(), 1)))
            {
                var nextWordSpan = context.TextStructureNavigator.GetNextWord(previousWordSpan.Value.End);

                if (nextWordSpan.HasValue)
                {
                    var previousWord = context.TextView.TextSnapshot.GetText(previousWordSpan.Value);
                    var nextWord = context.TextView.TextSnapshot.GetText(nextWordSpan.Value);

                    using (var edit = context.TextView.TextBuffer.CreateEdit())
                    {
                        edit.Replace(nextWordSpan.Value, previousWord);
                        edit.Replace(previousWordSpan.Value, nextWord);                        

                        edit.Apply();
                    }

                    context.TextView.Caret.MoveTo(new SnapshotPoint(context.TextView.TextSnapshot, nextWordSpan.Value.End));
                    context.TextView.Caret.EnsureVisible();
                }
            }
        }
Пример #8
0
        internal override void Execute(EmacsCommandContext context)
        {
            var currentLineDifference = context.TextBuffer.GetLineNumber(context.TextView.Caret.Position.BufferPosition) - context.TextBuffer.GetLineNumber(context.TextView.TextViewLines.FirstVisibleLine.Start);

            context.EditorOperations.ScrollPageDown();

            context.TextView.PositionCaretOnLine(currentLineDifference);
        }
Пример #9
0
        internal override void Execute(EmacsCommandContext context)
        {
            var currentLineDifference = context.TextBuffer.GetLineNumber(context.TextView.Caret.Position.BufferPosition) - context.TextBuffer.GetLineNumber(context.TextView.TextViewLines.FirstVisibleLine.Start);

            context.EditorOperations.ScrollPageDown();

            context.TextView.PositionCaretOnLine(currentLineDifference);
        }
Пример #10
0
		internal override void Execute(EmacsCommandContext context)
		{
			var rdt = context.Manager.ServiceProvider.GetService<SVsRunningDocumentTable, IVsRunningDocumentTable>();
			if (rdt != null)
			{
				rdt.SaveDocuments((uint)__VSRDTSAVEOPTIONS.RDTSAVEOPT_PromptSave, null, (uint)VSConstants.VSITEMID.Root, 0);
			}
		}
Пример #11
0
        internal override void ExecuteInverse(EmacsCommandContext context)
        {
            var caretPosition = context.TextView.GetCaretPosition().Position;

            if (caretPosition < context.TextBuffer.CurrentSnapshot.Length)
            {
                context.EditorOperations.Delete();
            }
        }
Пример #12
0
 internal override void Execute(EmacsCommandContext context)
 {
     if (context.UniversalArgument == 4)
         context.MarkSession.PopMark();
     else if (context.UniversalArgument == 16)
         context.MarkSession.RemoveTopMark();
     else
         context.MarkSession.PushMark();
 }
Пример #13
0
        internal override void Execute(EmacsCommandContext context)
        {
            var shell = context.Manager.ServiceProvider.GetService<SVsUIShell, IVsUIShell>();

            if (shell != null)
            {
                shell.PostExecCommand(typeof(VSConstants.VSStd97CmdID).GUID, (uint)VSConstants.VSStd97CmdID.GotoCommandLine, 0, 0);
            }
        }
        internal override void ExecuteInverse(EmacsCommandContext context)
        {
            var caretPosition = context.TextView.GetCaretPosition().Position;

            if (caretPosition < context.TextBuffer.CurrentSnapshot.Length)
            {
                context.EditorOperations.Delete();
            }
        }
Пример #15
0
        internal override void Execute(EmacsCommandContext context)
        {
            var rdt = context.Manager.ServiceProvider.GetService <SVsRunningDocumentTable, IVsRunningDocumentTable>();

            if (rdt != null)
            {
                rdt.SaveDocuments((uint)__VSRDTSAVEOPTIONS.RDTSAVEOPT_PromptSave, null, (uint)VSConstants.VSITEMID.Root, 0);
            }
        }
Пример #16
0
        internal override void Execute(EmacsCommandContext context)
        {
            // insert a newline right after the caret
            // context.editoroperations.insertnewline() is not working as expected for this scenario
            context.EditorOperations.InsertText(Environment.NewLine);

            // get the caret back to the location it was before the newline was inserted
            context.EditorOperations.MoveToPreviousCharacter();
        }
Пример #17
0
        internal override void Execute(EmacsCommandContext context)
        {
            var shell = context.Manager.ServiceProvider.GetService <SVsUIShell, IVsUIShell>();

            if (shell != null)
            {
                shell.PostExecCommand(typeof(VSConstants.VSStd97CmdID).GUID, (uint)VSConstants.VSStd97CmdID.GotoCommandLine, 0, 0);
            }
        }
Пример #18
0
        internal override void Execute(EmacsCommandContext context)
        {
            // insert a newline right after the caret
            // context.editoroperations.insertnewline() is not working as expected for this scenario
            context.EditorOperations.InsertText(Environment.NewLine);

            // get the caret back to the location it was before the newline was inserted
            context.EditorOperations.MoveToPreviousCharacter();
        }
 internal override void Execute(EmacsCommandContext context)
 {
     if (!context.TextView.Selection.IsEmpty)
     {
         context.EditorOperations.Delete();
     }
     else
     {
         context.Manager.UpdateStatus(Resources.OperationCannotBePerformedWithoutTextSelection);
     }
 }
Пример #20
0
        internal override void Execute(EmacsCommandContext context)
        {
            // In Emacs, if there's a selection and text is pasted, the selection is cleared first
            if (context.MarkSession.IsActive)
                context.MarkSession.Deactivate(clearSelection: true);

            // Push the mark represented by the current position of the caret
            context.MarkSession.PushMark(false);
            
            context.CommandRouter.ExecuteDTECommand("Edit.Paste");
        }
Пример #21
0
 internal override void Execute(EmacsCommandContext context)
 {
     if (context.Manager.AfterSearch)
     {
         context.EditorOperations.MoveCaretToStartOfPhysicalLine(false);
     }
     else
     {
         context.EditorOperations.MoveCaretToStartOfPhysicalLine();
     }
 }
Пример #22
0
 internal override void Execute(EmacsCommandContext context)
 {
     if (context.Manager.UniversalArgument > 0 && context.Manager.UniversalArgument <= 255)
     {
         context.EditorOperations.InsertText(((char)context.Manager.UniversalArgument.Value).ToString());
     }
     else
     {
         context.Manager.UpdateStatus("Use c-u to enter the ASCII decimal value first");
     }
 }
Пример #23
0
 internal override void Execute(EmacsCommandContext context)
 {
     if (context.Manager.AfterSearch)
     {
         context.EditorOperations.MoveCaretToEndOfPhysicalLine(false);
     }
     else
     {
         context.EditorOperations.MoveCaretToEndOfPhysicalLine();
     }
 }
        internal override void ExecuteInverse(EmacsCommandContext context)
        {
            var repeat = Math.Abs(context.Manager.GetUniversalArgumentOrDefault(1));

            context.EditorOperations.ScrollLineBottom();

            for (int i = 0; i < repeat; i++)
            {
                context.EditorOperations.ScrollDownAndMoveCaretIfNecessary();
            }
        }
        internal override void ExecuteInverse(EmacsCommandContext context)
        {
            var repeat = Math.Abs(context.Manager.GetUniversalArgumentOrDefault(1));

            context.EditorOperations.ScrollLineBottom();

            for (int i = 0; i < repeat; i++)
            {
                context.EditorOperations.ScrollDownAndMoveCaretIfNecessary();
            }
        }
Пример #26
0
 internal override void Execute(EmacsCommandContext context)
 {
     if (context.Manager.UniversalArgument > 0 && context.Manager.UniversalArgument <= 255)
     {
         context.EditorOperations.InsertText(((char)context.Manager.UniversalArgument.Value).ToString());
     }
     else
     {
         context.Manager.UpdateStatus("Use c-u to enter the ASCII decimal value first");
     }
 }
Пример #27
0
        internal override void Execute(EmacsCommandContext context)
        {
            // EditorOpertion.MoveNextWord is not working as expected for our spec.
            // For example: When the caret is in the middle of a word this command should
            // move the caret to the end of the same word. EditorOperations moves the caret
            // to the next word instead.

            var word = context.TextStructureNavigator.GetNextWord(context.TextView);

            if (word.HasValue)
                context.EditorOperations.MoveCaret(word.Value.End);
        }
Пример #28
0
        internal override void Execute(EmacsCommandContext context)
        {
            // we can't use the repeating support because of the special behavior of UniversalArgument=0
            if (!context.UniversalArgument.HasValue || context.Manager.UniversalArgument == 0)
            {
                ITextCaret    caret           = context.TextView.Caret;
                int           caretPosition   = caret.Position.BufferPosition.Position;
                ITextViewLine caretViewLine   = caret.ContainingTextViewLine;
                int           endOfLine       = caretViewLine.End.Position;
                int           startOfNextLine = caretViewLine.EndIncludingLineBreak.Position;

                if (caretPosition == endOfLine)
                {
                    context.EditorOperations.Delete(caretPosition, startOfNextLine - caretPosition);
                }
                else
                {
                    // does the line contain whitespaces from caret till the end?
                    for (int whitespaceChecker = caretPosition; ; ++whitespaceChecker)
                    {
                        if (whitespaceChecker <= endOfLine)
                        {
                            if (char.IsWhiteSpace(context.TextView.TextSnapshot[whitespaceChecker]))
                            {
                                continue;
                            }
                            else
                            {
                                context.EditorOperations.DeleteToEndOfPhysicalLine();
                                break;
                            }
                        }
                        else
                        {
                            // reached end of line and every character was a whitespace
                            context.EditorOperations.Delete(caretPosition, startOfNextLine - caretPosition);
                            break;
                        }
                    }
                }
            }
            else // (context.UniversalArgument > 0)
            {
                for (int count = context.Manager.GetUniversalArgumentOrDefault(1); count > 0; count--)
                {
                    int caretPosition = context.TextView.Caret.Position.BufferPosition.Position;
                    int nextLineStart = context.TextView.Caret.ContainingTextViewLine.EndIncludingLineBreak.Position;

                    context.EditorOperations.Delete(caretPosition, nextLineStart - caretPosition);
                }
            }
        }
Пример #29
0
        internal override void Execute(EmacsCommandContext context)
        {
            // In Emacs, if there's a selection and text is pasted, the selection is cleared first
            if (context.MarkSession.IsActive)
            {
                context.MarkSession.Deactivate(clearSelection: true);
            }

            // Push the mark represented by the current position of the caret
            context.MarkSession.PushMark(false);

            context.CommandRouter.ExecuteDTECommand("Edit.Paste");
        }
Пример #30
0
        internal override void Execute(EmacsCommandContext context)
        {
            var word = context.TextStructureNavigator.GetNextWord(context.TextView);

            if (word.HasValue)
            {
                var caretPosition = context.TextView.GetCaretPosition();
                var span          = new Span(caretPosition, word.Value.End - caretPosition);
                var text          = context.TextView.TextSnapshot.GetText(span);

                context.TextBuffer.Replace(span, TransformText(text));
            }
        }
Пример #31
0
        internal override void Execute(EmacsCommandContext context)
        {
            var word = context.TextStructureNavigator.GetNextWord(context.TextView);

            if (word.HasValue)
            {
                var caretPosition = context.TextView.GetCaretPosition();
                var span = new Span(caretPosition, word.Value.End - caretPosition);
                var text = context.TextView.TextSnapshot.GetText(span);

                context.TextBuffer.Replace(span, TransformText(text));
            }
        }
        internal override void Execute(EmacsCommandContext context)
        {
            // we can't use the repeating support because of the special behavior of UniversalArgument=0
            if (context.Manager.UniversalArgument == 0)
            {
                ITextCaret caret = context.TextView.Caret;
                int caretPosition = caret.Position.BufferPosition.Position;
                ITextViewLine caretViewLine = caret.ContainingTextViewLine;
                int endOfLine = caretViewLine.End.Position;
                int startOfNextLine = caretViewLine.EndIncludingLineBreak.Position;

                if (caretPosition == endOfLine)
                {
                    context.EditorOperations.Delete(caretPosition, startOfNextLine - caretPosition);
                }
                else
                {
                    // does the line contain whitespaces from caret till the end?
                    for (int whitespaceChecker = caretPosition; ; ++whitespaceChecker)
                    {
                        if (whitespaceChecker <= endOfLine)
                        {
                            if (char.IsWhiteSpace(context.TextView.TextSnapshot[whitespaceChecker]))
                            {
                                continue;
                            }
                            else
                            {
                                context.EditorOperations.DeleteToEndOfPhysicalLine();
                                break;
                            }
                        }
                        else
                        {
                            // reached end of line and every character was a whitespace
                            context.EditorOperations.Delete(caretPosition, startOfNextLine - caretPosition);
                        }
                    }
                }
            }
            else if (!context.UniversalArgument.HasValue || context.UniversalArgument > 0)
            {
                for (int count = context.Manager.GetUniversalArgumentOrDefault(1); count > 0; count--)
                {
                    int caretPosition = context.TextView.Caret.Position.BufferPosition.Position;
                    int nextLineStart = context.TextView.Caret.ContainingTextViewLine.EndIncludingLineBreak.Position;

                    context.EditorOperations.Delete(caretPosition, nextLineStart - caretPosition);
                }
            }
        }
Пример #33
0
        internal override void Execute(EmacsCommandContext context)
        {
            // EditorOpertion.MoveNextWord is not working as expected for our spec.
            // For example: When the caret is in the middle of a word this command should
            // move the caret to the end of the same word. EditorOperations moves the caret
            // to the next word instead.

            var word = context.TextStructureNavigator.GetNextWord(context.TextView);

            if (word.HasValue)
            {
                context.EditorOperations.MoveCaret(word.Value.End);
            }
        }
Пример #34
0
        internal override void Execute(EmacsCommandContext context)
        {
            DTE vs = context.Manager.ServiceProvider.GetService<DTE>();

            if (vs.ActiveDocument != null && vs.ActiveDocument.ActiveWindow != null)
            {
                var textWindow = vs.ActiveDocument.ActiveWindow.Object as TextWindow;

                if (textWindow != null && textWindow.Panes.Count == 1)
                {
                    context.CommandRouter.ExecuteDTECommand("Window.Split");
                }
            }                      
        }
        internal override void Execute(EmacsCommandContext context)
        {
            DTE vs = context.Manager.ServiceProvider.GetService <DTE>();

            if (vs.ActiveDocument != null && vs.ActiveDocument.ActiveWindow != null)
            {
                var textWindow = vs.ActiveDocument.ActiveWindow.Object as TextWindow;

                if (textWindow != null && textWindow.Panes.Count == 2)
                {
                    context.CommandRouter.ExecuteDTECommand("Window.Split");
                }
            }
        }
Пример #36
0
 internal override void Execute(EmacsCommandContext context)
 {
     if (context.UniversalArgument == 4)
     {
         context.MarkSession.PopMark();
     }
     else if (context.UniversalArgument == 16)
     {
         context.MarkSession.RemoveTopMark();
     }
     else
     {
         context.MarkSession.PushMark();
     }
 }
Пример #37
0
        internal override void ExecuteInverse(EmacsCommandContext context)
        {
            var word = context.TextStructureNavigator.GetPreviousWord(context.TextView);

            if (word.HasValue)
            {
                var caretPosition = context.TextView.GetCaretPosition();
                var span = new Span(word.Value.Start, caretPosition - word.Value.Start);
                var text = context.TextView.TextSnapshot.GetText(span);

                context.TextBuffer.Replace(span, TransformText(text));

                context.EditorOperations.MoveCaret(span.Start);
            }
        }
Пример #38
0
        internal override void ExecuteInverse(EmacsCommandContext context)
        {
            var word = context.TextStructureNavigator.GetPreviousWord(context.TextView);

            if (word.HasValue)
            {
                var caretPosition = context.TextView.GetCaretPosition();
                var span          = new Span(word.Value.Start, caretPosition - word.Value.Start);
                var text          = context.TextView.TextSnapshot.GetText(span);

                context.TextBuffer.Replace(span, TransformText(text));

                context.EditorOperations.MoveCaret(span.Start);
            }
        }
Пример #39
0
        internal override void Execute(EmacsCommandContext context)
        {
            var word = context.TextStructureNavigator.GetNextWord(context.TextView);

            if(word.HasValue)
            {
                if (context.TextView.GetCaretPosition().Position < word.Value.Start)
                    context.EditorOperations.MoveCaret(word.Value.Start);

                context.EditorOperations.MakeUppercase();
                for (int position = context.TextView.GetCaretPosition().Position; position < word.Value.End; position++)
                {
                    context.EditorOperations.MakeLowercase();
                }
            }            
        }
Пример #40
0
        internal override void Execute(EmacsCommandContext context)
        {
            var word = context.TextStructureNavigator.GetNextWord(context.TextView);

            if (word.HasValue)
            {
                if (context.TextView.GetCaretPosition().Position < word.Value.Start)
                {
                    context.EditorOperations.MoveCaret(word.Value.Start);
                }

                context.EditorOperations.MakeUppercase();
                for (int position = context.TextView.GetCaretPosition().Position; position < word.Value.End; position++)
                {
                    context.EditorOperations.MakeLowercase();
                }
            }
        }
Пример #41
0
        internal override void Execute(EmacsCommandContext context)
        {
            // Save the line number before applying the break command
            var lineNumber = context.TextView.TextViewLines.IndexOf(context.TextView.Caret.ContainingTextViewLine);

            // Execute the VS break command to support the commit of intellisense session
            context.CommandRouter.ExecuteDTECommand(VsCommands.BreakLineCommandName);

            // Check if the break command has changed the caret position.
            // If the caret position has not changed it means that someone else
            // has executed the break line command. For example: comitting an
            // intellisense session.
            if (lineNumber != context.TextView.TextViewLines.IndexOf(context.TextView.Caret.ContainingTextViewLine))
            {
                // Ensure the caret is at the beginning of the inserted line
                context.EditorOperations.MoveToStartOfLine();
            }
        }
Пример #42
0
        internal override void Execute(EmacsCommandContext context)
        {
            // Save the line number before applying the break command
            var lineNumber = context.TextView.TextViewLines.IndexOf(context.TextView.Caret.ContainingTextViewLine);

            // Execute the VS break command to support the commit of intellisense session
            context.CommandRouter.ExecuteDTECommand(VsCommands.BreakLineCommandName);

            // Check if the break command has changed the caret position.
            // If the caret position has not changed it means that someone else
            // has executed the break line command. For example: comitting an
            // intellisense session.
            if (lineNumber != context.TextView.TextViewLines.IndexOf(context.TextView.Caret.ContainingTextViewLine))
            {
                // Ensure the caret is at the beginning of the inserted line
                context.EditorOperations.MoveToStartOfLine();
            }
        }
        internal override void Execute(EmacsCommandContext context)
        {
            SnapshotSpan? word = null;

            for (var counter = context.Manager.GetUniversalArgumentOrDefault(1); counter > 0; counter--)
            {
                if (word.HasValue)
                    word = context.TextStructureNavigator.GetPreviousWord(word.Value.Start);
                else
                    word = context.TextStructureNavigator.GetPreviousWord(context.TextView);
            }

            if (word.HasValue)
            {
                var caretPosition = context.TextView.GetCaretPosition();
                context.EditorOperations.Delete(word.Value.Start, caretPosition - word.Value.Start);
            }
        }
        internal override void Execute(EmacsCommandContext context)
        {
            var caretPosition = context.TextView.GetCaretPosition().Position;

            if (caretPosition > 0)
            {
                if (context.TextBuffer.CurrentSnapshot.GetText(context.TextView.GetCaretPosition() - 1, 1) == "\t")
                {
                    context.TextView.Selection.Select(new Text.SnapshotSpan(context.TextView.TextSnapshot, new Span(caretPosition - 1, 1)), false);
                    context.EditorOperations.ConvertTabsToSpaces();
                    context.MarkSession.Deactivate();
                    context.EditorOperations.Backspace();
                }
                else
                {
                    context.EditorOperations.Backspace();
                }
            }
        }
Пример #45
0
        internal override void Execute(EmacsCommandContext context)
        {
            var caretPosition = context.TextView.GetCaretPosition().Position;

            if (caretPosition > 0)
            {
                if (context.TextBuffer.CurrentSnapshot.GetText(context.TextView.GetCaretPosition() - 1, 1) == "\t")
                {
                    context.TextView.Selection.Select(new Text.SnapshotSpan(context.TextView.TextSnapshot, new Span(caretPosition - 1, 1)), false);
                    context.EditorOperations.ConvertTabsToSpaces();
                    context.MarkSession.Deactivate();
                    context.EditorOperations.Backspace();
                }
                else
                {
                    context.EditorOperations.Backspace();
                }
            }
        }
Пример #46
0
        internal override void Execute(EmacsCommandContext context)
        {
            ITextSelection textSelection = context.TextView.Selection;

            if (!textSelection.IsEmpty)
            {
                // Don't support addition of box selection to the clipboard ring yet
                if (textSelection.Mode == TextSelectionMode.Stream)
                {
                    context.Manager.ClipboardRing.Add(textSelection.StreamSelectionSpan.GetText());
                }

                context.CommandRouter.ExecuteDTECommand("Edit.Cut");
            }
            else
            {
                context.Manager.UpdateStatus(Resources.OperationCannotBePerformedWithoutTextSelection);
            }
        }
Пример #47
0
        internal override void Execute(EmacsCommandContext context)
        {
            ITextSelection textSelection = context.TextView.Selection;

            if (!textSelection.IsEmpty)
            {
                // Don't support addition of box selection to the clipboard ring yet
                if (textSelection.Mode == TextSelectionMode.Stream)
                {
                    context.Manager.ClipboardRing.Add(textSelection.StreamSelectionSpan.GetText());
                }

                context.CommandRouter.ExecuteDTECommand("Edit.Cut");
            }
            else
            {
                context.Manager.UpdateStatus(Resources.OperationCannotBePerformedWithoutTextSelection);
            }
        }
Пример #48
0
        internal override void Execute(EmacsCommandContext context)
        {
            ITextSelection textSelection = context.TextView.Selection;

            if (!textSelection.IsEmpty)
            {
                // Don't support addition of box selection to the clipboard ring yet
                if (textSelection.Mode == TextSelectionMode.Stream)
                {
                    context.Manager.ClipboardRing.Add(textSelection.StreamSelectionSpan.GetText());
                }

                context.CommandRouter.ExecuteDTECommand("Edit.Copy");
            }
            else
            {
                context.Manager.UpdateStatus("The region is not active");
            }
        }        
Пример #49
0
        internal override void Execute(EmacsCommandContext context)
        {
            ITextSelection textSelection = context.TextView.Selection;

            if (!textSelection.IsEmpty)
            {
                // Don't support addition of box selection to the clipboard ring yet
                if (textSelection.Mode == TextSelectionMode.Stream)
                {
                    context.Manager.ClipboardRing.Add(textSelection.StreamSelectionSpan.GetText());
                }

                context.CommandRouter.ExecuteDTECommand("Edit.Copy");
            }
            else
            {
                context.Manager.UpdateStatus("The region is not active");
            }
        }
Пример #50
0
        internal override void ExecuteInverse(EmacsCommandContext context)
        {
            var word = context.TextStructureNavigator.GetPreviousWord(context.TextView);

            if (word.HasValue)
            {
                if (context.TextView.GetCaretPosition().Position > word.Value.End)
                    context.EditorOperations.MoveCaret(word.Value.End);

                var wordStart = word.Value.Start.Position;

                for (int position = context.TextView.GetCaretPosition().Position - 1; position > wordStart; position--)
                {
                    context.EditorOperations.MoveCaret(position);
                    context.EditorOperations.MakeLowercase();
                }

                context.EditorOperations.MoveCaret(wordStart);
                context.EditorOperations.MakeUppercase();
                context.EditorOperations.MoveCaret(wordStart);
            }
        }
        internal override void Execute(EmacsCommandContext context)
        {
            SnapshotSpan?word = null;

            for (var counter = context.Manager.GetUniversalArgumentOrDefault(1); counter > 0; counter--)
            {
                if (word.HasValue)
                {
                    word = context.TextStructureNavigator.GetPreviousWord(word.Value.Start);
                }
                else
                {
                    word = context.TextStructureNavigator.GetPreviousWord(context.TextView);
                }
            }

            if (word.HasValue)
            {
                var caretPosition = context.TextView.GetCaretPosition();
                context.EditorOperations.Delete(word.Value.Start, caretPosition - word.Value.Start);
            }
        }
        internal override void Execute(EmacsCommandContext context)
        {
            // TODO: Add universal argument support (P3?)
            //From the gnu-emacs manual (I think this is P3 since most people don’t know about it, and it is rarely used):
            //Another way to do scrolling is with C-l with a numeric argument. C-l does not clear the screen when given an argument; it only scrolls the selected window. With a positive argument n, it repositions text to put point n lines down from the top. An argument of zero puts point on the very top line. Point does not move with respect to the text; rather, the text and point move rigidly on the screen. C-l with a negative argument puts point that many lines from the bottom of the window. For example, C-u - 1 C-l puts point on the bottom line, and C-u - 5 C-l puts it five lines from the bottom. Just C-u as argument, as in C-u C-l, scrolls point to the center of the selected window. 
            //If the prefix arg is greater than the display lines of the window, just go that many lines down and redisplay.

            if (context.Manager.UniversalArgument.HasValue)
            {
                var repeat = context.Manager.UniversalArgument.Value;

                context.EditorOperations.ScrollLineTop();

                for (int i = 0; i < repeat; i++)
                {
                    context.EditorOperations.ScrollUpAndMoveCaretIfNecessary();
                }
            }
            else
            {
                context.EditorOperations.ScrollLineCenter();
            }
        }
        internal override void Execute(EmacsCommandContext context)
        {
            // TODO: Add universal argument support (P3?)
            //From the gnu-emacs manual (I think this is P3 since most people don’t know about it, and it is rarely used):
            //Another way to do scrolling is with C-l with a numeric argument. C-l does not clear the screen when given an argument; it only scrolls the selected window. With a positive argument n, it repositions text to put point n lines down from the top. An argument of zero puts point on the very top line. Point does not move with respect to the text; rather, the text and point move rigidly on the screen. C-l with a negative argument puts point that many lines from the bottom of the window. For example, C-u - 1 C-l puts point on the bottom line, and C-u - 5 C-l puts it five lines from the bottom. Just C-u as argument, as in C-u C-l, scrolls point to the center of the selected window.
            //If the prefix arg is greater than the display lines of the window, just go that many lines down and redisplay.

            if (context.Manager.UniversalArgument.HasValue)
            {
                var repeat = context.Manager.UniversalArgument.Value;

                context.EditorOperations.ScrollLineTop();

                for (int i = 0; i < repeat; i++)
                {
                    context.EditorOperations.ScrollUpAndMoveCaretIfNecessary();
                }
            }
            else
            {
                context.EditorOperations.ScrollLineCenter();
            }
        }
Пример #54
0
        internal override void ExecuteInverse(EmacsCommandContext context)
        {
            var word = context.TextStructureNavigator.GetPreviousWord(context.TextView);

            if (word.HasValue)
            {
                if (context.TextView.GetCaretPosition().Position > word.Value.End)
                {
                    context.EditorOperations.MoveCaret(word.Value.End);
                }

                var wordStart = word.Value.Start.Position;

                for (int position = context.TextView.GetCaretPosition().Position - 1; position > wordStart; position--)
                {
                    context.EditorOperations.MoveCaret(position);
                    context.EditorOperations.MakeLowercase();
                }

                context.EditorOperations.MoveCaret(wordStart);
                context.EditorOperations.MakeUppercase();
                context.EditorOperations.MoveCaret(wordStart);
            }
        }
Пример #55
0
        internal override void Execute(EmacsCommandContext context)
        {
            ITextSelection selection = context.TextView.Selection;
            bool trackCaret = true;
            bool markSessionActive = context.MarkSession.IsActive;

            // Return immediately if the buffer is read-only.
            if (context.TextBuffer.IsReadOnly(selection.Start.Position.GetContainingLine().Extent))
            {
                return;
            }

            // If there's not a multi-line selection, then clear it and setup for line indentation
            if (!selection.IsEmpty)
            {
                if (selection.Mode == TextSelectionMode.Box)
                {
                    return;
                }
                else
                {
                    VirtualSnapshotSpan selectionSpan = selection.StreamSelectionSpan;

                    if (selectionSpan.Start.Position.GetContainingLine().LineNumber != selectionSpan.End.Position.GetContainingLine().LineNumber)
                    {
                        return;
                    }

                    selection.Clear();

                    // Since there was a selection on the line before the format, we are not obligated to place the caret at a specific place
                    // after the format operation is done
                    trackCaret = false;
                }
            }

            // Strip any existing whitespace to setup the line for formatting
            this.StripWhiteSpace(context.TextView.GetCaretPosition().GetContainingLine());

            int? indentation = context.Manager.SmartIndentationService.GetDesiredIndentation(context.TextView, context.TextView.GetCaretPosition().GetContainingLine());

            if (indentation.HasValue)
            {
                // Insert the desired indentation level
                context.TextBuffer.Insert(context.TextView.GetCaretPosition().GetContainingLine().Start, new string(' ', indentation.Value));

                // Finally, are any tab/spaces conversions necessary?
                if (!context.TextView.Options.IsConvertTabsToSpacesEnabled())
                {
                    context.EditorOperations.ConvertSpacesToTabs();
                }
            }
            else
            {
                // We couldn't find any indentation level for the line, try executing the format command as the last resort

                // Remember caret position
                int caretOffsetFromStart = 0;

                if (trackCaret)
                {
                    CaretPosition positionBeforeChange = context.TextView.Caret.Position;
                    context.EditorOperations.MoveToStartOfLineAfterWhiteSpace(false);
                    caretOffsetFromStart = positionBeforeChange.BufferPosition.Position - context.TextView.GetCaretPosition();
                }

                // Format
                context.EditorOperations.SelectAndMoveCaret(
                    new VirtualSnapshotPoint(context.TextView.GetCaretPosition().GetContainingLine().Start, 0),
                    new VirtualSnapshotPoint(context.TextView.GetCaretPosition().GetContainingLine().End, 0));

                context.CommandRouter.ExecuteDTECommand("Edit.FormatSelection");

                // Move to beginning of newly indented line after format operation is done
                context.EditorOperations.MoveToStartOfLineAfterWhiteSpace(false);

                // Restore the position of the caret
                if (caretOffsetFromStart > 0)
                {
                    context.EditorOperations.MoveCaret(context.TextView.Caret.Position.BufferPosition + caretOffsetFromStart, false);
                }
            }

            // Ensure we restore the state of the mark session after the formatting operation (changing selection activates
            // the mark session automatically and we change the selection during our formatting operation).
            if (!markSessionActive)
            {
                context.MarkSession.Deactivate();
            }
        }
Пример #56
0
 internal override void Execute(EmacsCommandContext context)
 {
     context.MarkSession.PushMark(activateSession: false);
     context.EditorOperations.MoveToEndOfDocument();
 }
Пример #57
0
 internal override void Execute(EmacsCommandContext context)
 {
     context.CommandRouter.ExecuteDTECommand(VsCommands.BreakLineCommandName);
 }
        internal override void Execute(EmacsCommandContext context)
        {
            var session = UniversalArgumentSession.GetSession(context.TextView);

            session.Start();
        }
Пример #59
0
 internal override void ExecuteInverse(EmacsCommandContext context)
 {
     // do nothing
 }
Пример #60
0
 internal override void ExecuteInverse(EmacsCommandContext context)
 {
     // do nothing
 }