示例#1
0
            /// <summary>
            /// Appends given text to the last input span (standard input or active code input).
            /// </summary>
            private void AppendInput(string text)
            {
                var snapshot  = _window._projectionBuffer.CurrentSnapshot;
                var spanCount = snapshot.SpanCount;
                var inputSpan = snapshot.GetSourceSpan(spanCount - 1);

                Debug.Assert(_window.GetSpanKind(inputSpan.Snapshot) == ReplSpanKind.Language ||
                             _window.GetSpanKind(inputSpan.Snapshot) == ReplSpanKind.StandardInput);

                var buffer = inputSpan.Snapshot.TextBuffer;
                var span   = inputSpan.Span;

                using (var edit = buffer.CreateEdit())
                {
                    edit.Insert(edit.Snapshot.Length, text);
                    edit.Apply();
                }

                var replSpan = new CustomTrackingSpan(
                    buffer.CurrentSnapshot,
                    new Span(span.Start, span.Length + text.Length),
                    PointTrackingMode.Negative,
                    PointTrackingMode.Positive);

                ReplaceProjectionSpan(spanCount - 1, replSpan);

                _window.Caret.EnsureVisible();
            }
            public async Task <ExecutionResult> ResetAsync(bool initialize)
            {
                try
                {
                    Debug.Assert(State != State.Resetting, "The button should have been disabled.");

                    if (_window._stdInputStart != null)
                    {
                        CancelStandardInput();
                    }

                    _window._buffer.Flush();

                    if (State == State.WaitingForInput)
                    {
                        var snapshot  = _window._projectionBuffer.CurrentSnapshot;
                        var spanCount = snapshot.SpanCount;
                        Debug.Assert(_window.GetSpanKind(snapshot.GetSourceSpan(spanCount - 1)) == ReplSpanKind.Language);
                        StoreUncommittedInput();
                        RemoveProjectionSpans(spanCount - 2, 2);
                        _window._currentLanguageBuffer = null;
                    }

                    State = State.Resetting;
                    var executionResult = await _window._evaluator.ResetAsync(initialize).ConfigureAwait(true);

                    Debug.Assert(_window.OnUIThread()); // ConfigureAwait should bring us back to the UI thread.

                    Debug.Assert(State == State.Resetting, $"Unexpected state {State}");
                    FinishExecute(executionResult.IsSuccessful);

                    return(executionResult);
                }
                catch (Exception e) when(_window.ReportAndPropagateException(e))
                {
                    throw ExceptionUtilities.Unreachable;
                }
            }