Esempio n. 1
0
        internal override void Execute(EmacsCommandContext context)
        {
            int viewLine = context.TextBuffer.GetLineNumber(context.TextView.Caret.Position.BufferPosition) -
                           context.TextBuffer.GetLineNumber(context.TextView.TextViewLines.FirstVisibleLine.Start);

            context.EditorOperations.ScrollPageDown();
            context.TextView.PositionCaretOnLine(viewLine);
        }
Esempio n. 2
0
        internal override void Execute(EmacsCommandContext context)
        {
            int num = context.TextView.TextViewLines.IndexOf(context.TextView.Caret.ContainingTextViewLine);

            context.CommandRouter.ExecuteDTECommand("Edit.BreakLine");
            if (num == context.TextView.TextViewLines.IndexOf(context.TextView.Caret.ContainingTextViewLine))
            {
                return;
            }
            context.EditorOperations.MoveToStartOfLine();
        }
Esempio n. 3
0
 internal override void Execute(EmacsCommandContext context)
 {
     if (!context.TextView.Selection.IsEmpty)
     {
         context.EditorOperations.Delete();
     }
     else
     {
         context.Manager.UpdateStatus(Resources.OperationCannotBePerformedWithoutTextSelection, false);
     }
 }
Esempio n. 4
0
 internal override void Execute(EmacsCommandContext context)
 {
     if (context.Manager.AfterSearch)
     {
         context.EditorOperations.MoveCaretToStartOfPhysicalLine(false);
     }
     else
     {
         context.EditorOperations.MoveCaretToStartOfPhysicalLine();
     }
 }
Esempio n. 5
0
        internal override void Execute(EmacsCommandContext context)
        {
            int?universalArgument1 = context.Manager.UniversalArgument;

            if ((universalArgument1.GetValueOrDefault() <= 0 ? 0 : (universalArgument1.HasValue ? 1 : 0)) != 0)
            {
                int?universalArgument2 = context.Manager.UniversalArgument;
                if ((universalArgument2.GetValueOrDefault() > (int)byte.MaxValue
                    ? 0
                    : (universalArgument2.HasValue ? 1 : 0)) != 0)
                {
                    context.EditorOperations.InsertText(((char)context.Manager.UniversalArgument.Value).ToString());
                    return;
                }
            }
            context.Manager.UpdateStatus("Use c-u to enter the ASCII decimal value first", false);
        }
Esempio n. 6
0
 internal override void Execute(EmacsCommandContext context)
 {
     if (context.Manager.UniversalArgument.HasValue)
     {
         int 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
     {
         context.CommandRouter.ExecuteDTECommand("Edit.GoTo");
     }
 }
 internal override void Execute(EmacsCommandContext context)
 {
     context.MarkSession.SwapPointAndMark();
 }
Esempio n. 8
0
 internal override void Execute(EmacsCommandContext context)
 {
     context.MarkSession.Activate();
 }
Esempio n. 9
0
 internal override void Execute(EmacsCommandContext context)
 {
     context.EditorOperations.TransposeCharacter();
 }
Esempio n. 10
0
 internal override void Execute(EmacsCommandContext context)
 {
     context.EditorOperations.MoveToNextCharacter();
 }
Esempio n. 11
0
 internal override void Execute(EmacsCommandContext context)
 {
     context.Manager.ClearStatus();
 }
Esempio n. 12
0
 internal override void Execute(EmacsCommandContext context)
 {
     context.CommandRouter.ExecuteDTECommand("Edit.BreakLine");
 }
Esempio n. 13
0
 internal override void Execute(EmacsCommandContext context)
 {
     context.MarkSession.PushMark(false);
     context.EditorOperations.MoveToEndOfDocument();
 }
Esempio n. 14
0
 internal override void Execute(EmacsCommandContext context)
 {
     context.EditorOperations.ScrollLineTop();
 }
Esempio n. 15
0
 internal override void Execute(EmacsCommandContext context)
 {
     context.EditorOperations.MoveLineDown();
 }
Esempio n. 16
0
 internal override void Execute(EmacsCommandContext context)
 {
     UniversalArgumentSession.GetSession(context.TextView).Start();
 }
Esempio n. 17
0
 internal override void ExecuteInverse(EmacsCommandContext context)
 {
 }
Esempio n. 18
0
 public void Execute(ITextView view, IEmacsCommandMetadata metadata, bool evaluateUniversalArgument = true)
 {
     try
     {
         changes = new StringBuilder();
         view.TextBuffer.Changed += OnTextBufferChanged;
         EmacsCommand          command      = CreateCommand(metadata);
         EmacsCommand          emacsCommand = null;
         IEmacsCommandMetadata metadata1    = null;
         var context = new EmacsCommandContext(this, TextStructureNavigatorSelectorService,
                                               EditorOperationsFactoryService.GetEditorOperations(view), view,
                                               CommandRouterProvider.GetCommandRouter(view));
         if (ClipboardRing.Count == 0 || ClipboardRing.Last() != Clipboard.GetText())
         {
             ClipboardRing.Add(Clipboard.GetText());
         }
         if (command == null)
         {
             return;
         }
         ITextUndoHistory history = TextUndoHistoryRegistry.GetHistory(context.TextBuffer);
         using (ITextUndoTransaction transaction = CreateTransaction(metadata, history))
         {
             int  num  = 1;
             bool flag = false;
             if (evaluateUniversalArgument)
             {
                 flag = GetUniversalArgumentOrDefault(0) < 0;
                 if (flag)
                 {
                     metadata1    = GetCommandMetadata(metadata.InverseCommand);
                     emacsCommand = CreateCommand(metadata1);
                 }
                 if (metadata.CanBeRepeated)
                 {
                     num = Math.Abs(GetUniversalArgumentOrDefault(1));
                 }
             }
             for (; num > 0; --num)
             {
                 if (flag)
                 {
                     if (emacsCommand != null)
                     {
                         emacsCommand.Execute(context);
                     }
                     else
                     {
                         command.ExecuteInverse(context);
                     }
                 }
                 else
                 {
                     command.Execute(context);
                 }
             }
             if (transaction != null)
             {
                 transaction.Complete();
             }
             if (context.Clipboard.Length > 0)
             {
                 ClipboardRing.Add(context.Clipboard.ToString());
                 Clipboard.SetText(context.Clipboard.ToString());
             }
             else if (changes.Length > 0 && metadata.CopyDeletedTextToTheClipboard)
             {
                 ClipboardRing.Add(changes.ToString());
                 Clipboard.SetText(changes.ToString());
             }
             LastExecutedCommand = flag ? metadata1 : metadata;
         }
     }
     catch (NoOperationException ex)
     {
     }
     finally
     {
         view.TextBuffer.Changed -= OnTextBufferChanged;
     }
 }
Esempio n. 19
0
        /// <summary>
        /// Executes the emacs command
        /// </summary>
        /// <param name="view"></param>
        /// <param name="metadata"></param>
        public void Execute(ITextView view, IEmacsCommandMetadata metadata, bool evaluateUniversalArgument = true)
        {
            using (BufferMonitor bufferMonitor = BufferMonitor.Create(view.TextBuffer))
            {
                try
                {
                    EmacsCommand          command                = CreateCommand(metadata);
                    EmacsCommand          inverseCommand         = null;
                    IEmacsCommandMetadata inverseCommandMetadata = null;

                    var context = new EmacsCommandContext(
                        this, this.TextStructureNavigatorSelectorService,
                        this.EditorOperationsFactoryService.GetEditorOperations(view),
                        view, CommandRouterProvider.GetCommandRouter(view));

                    if (command != null)
                    {
                        var history = this.TextUndoHistoryRegistry.GetHistory(context.TextBuffer);
                        using (var transaction = CreateTransaction(metadata, history))
                        {
                            var  repeatCount          = 1;
                            bool shouldExecuteInverse = false;

                            if (evaluateUniversalArgument)
                            {
                                // Check if we should execute the inverse logic of the command by checking if the universal argument is lower than 0
                                shouldExecuteInverse = GetUniversalArgumentOrDefault() < 0;
                                if (shouldExecuteInverse)
                                {
                                    // Search the inverse command using the metadata
                                    inverseCommandMetadata = GetCommandMetadata(metadata.InverseCommand);
                                    inverseCommand         = CreateCommand(inverseCommandMetadata);
                                }

                                // If the command specifies that can be repeated use the universal argument as the counter, otherwise execute the command only once.
                                if (metadata.CanBeRepeated)
                                {
                                    repeatCount = Math.Abs(GetUniversalArgumentOrDefault(1));
                                }
                            }

                            for (; repeatCount > 0; repeatCount--)
                            {
                                if (shouldExecuteInverse)
                                {
                                    // Execute the inverse logic
                                    if (inverseCommand != null)
                                    {
                                        inverseCommand.Execute(context);
                                    }
                                    else
                                    {
                                        command.ExecuteInverse(context);
                                    }
                                }
                                else
                                {
                                    // Execute the normal logic
                                    command.Execute(context);
                                }
                            }

                            // TODO: Check command error and rollback the transaction
                            if (transaction != null)
                            {
                                transaction.Complete();
                            }

                            // If the command executed was a kill command, then we want to append the text that was cut
                            // to any currently text cut for the view.
                            // If the command is not a kill command and we have had some cut commands executed previously
                            // that accumulated deleted text, then we want to put the data on the clipboard and reset
                            // the accumulated text.
                            if (metadata.IsKillCommand)
                            {
                                view.AppendKillString(bufferMonitor.BufferChanges);
                            }
                            else
                            {
                                view.FlushKillSring(this.ClipboardRing);
                            }

                            this.LastExecutedCommand = shouldExecuteInverse ? inverseCommandMetadata : metadata;
                        }
                    }
                }
                catch (NoOperationException)
                {
                    // Do nothing
                }
            }
        }
Esempio n. 20
0
 internal override void Execute(EmacsCommandContext context)
 {
     context.EditorOperations.MoveToTopOfView();
 }