Пример #1
0
        private void CopyToWindow(IInteractiveWindow window, CopyToInteractiveCommandArgs args, CommandExecutionContext context)
        {
            var buffer = window.CurrentLanguageBuffer;

            Debug.Assert(buffer != null);

            using (var edit = buffer.CreateEdit())
                using (var waitScope = context.OperationContext.AddScope(allowCancellation: true,
                                                                         InteractiveEditorFeaturesResources.Copying_selection_to_Interactive_Window))
                {
                    var text = GetSelectedText(args, context.OperationContext.UserCancellationToken);

                    // If the last line isn't empty in the existing submission buffer, we will prepend a
                    // newline
                    var lastLine = buffer.CurrentSnapshot.GetLineFromLineNumber(buffer.CurrentSnapshot.LineCount - 1);
                    if (lastLine.Extent.Length > 0)
                    {
                        var editorOptions = _editorOptionsFactoryService.GetOptions(args.SubjectBuffer);
                        text = editorOptions.GetNewLineCharacter() + text;
                    }

                    edit.Insert(buffer.CurrentSnapshot.Length, text);
                    edit.Apply();
                }

            // Move the caret to the end
            var editorOperations = _editorOperationsFactoryService.GetEditorOperations(window.TextView);
            var endPoint         = new VirtualSnapshotPoint(window.TextView.TextBuffer.CurrentSnapshot, window.TextView.TextBuffer.CurrentSnapshot.Length);

            editorOperations.SelectAndMoveCaret(endPoint, endPoint);
        }
        public CommandState GetStateForCopyToInteractive()
        {
            var copyToInteractiveArgs = new CopyToInteractiveCommandArgs(TextView, SubjectBuffer);

            return(CopyToInteractiveCommandHandler.GetCommandState(
                       copyToInteractiveArgs, () => { return CommandState.Unavailable; }));
        }
Пример #3
0
        bool ICommandHandler <CopyToInteractiveCommandArgs> .ExecuteCommand(
            CopyToInteractiveCommandArgs args,
            CommandExecutionContext context
            )
        {
            var window = OpenInteractiveWindow(focus: true);
            var buffer = window.CurrentLanguageBuffer;

            if (buffer != null)
            {
                CopyToWindow(window, args, context);
            }
            else
            {
                Action action = null;
                action = new Action(
                    () =>
                {
                    window.ReadyForInput -= action;
                    CopyToWindow(window, args, context);
                }
                    );

                window.ReadyForInput += action;
            }

            return(true);
        }
Пример #4
0
        public void SendCopyToInteractive()
        {
            var copyToInteractiveArgs = new CopyToInteractiveCommandArgs(TextView, SubjectBuffer);

            CopyToInteractiveCommandHandler.ExecuteCommand(
                copyToInteractiveArgs,
                TestCommandExecutionContext.Create()
                );
        }
Пример #5
0
 CommandState ICommandHandler <CopyToInteractiveCommandArgs> .GetCommandState(CopyToInteractiveCommandArgs args)
 => CommandState.Available;
Пример #6
0
 VSCommanding.CommandState VSCommanding.ICommandHandler <CopyToInteractiveCommandArgs> .GetCommandState(CopyToInteractiveCommandArgs args)
 {
     return(VSCommanding.CommandState.Available);
 }
        public void SendCopyToInteractive()
        {
            var copyToInteractiveArgs = new CopyToInteractiveCommandArgs(TextView, SubjectBuffer);

            CopyToInteractiveCommandHandler.ExecuteCommand(copyToInteractiveArgs, () => { });
        }
 CommandState ICommandHandler <CopyToInteractiveCommandArgs> .GetCommandState(CopyToInteractiveCommandArgs args, Func <CommandState> nextHandler)
 {
     return(GetSelectedSpans(args).Any() ? CommandState.Available : CommandState.Unavailable);
 }
Пример #9
0
 CommandState ICommandHandler <CopyToInteractiveCommandArgs> .GetCommandState(CopyToInteractiveCommandArgs args, Func <CommandState> nextHandler)
 {
     return(CommandState.Available);
 }