private static IEnumerable <string> GetActiveInputs(IWpfTextView activeView, PythonReplEvaluator eval) { return(eval.JoinCode(activeView.Selection.SelectedSpans.SelectMany(s => eval.SplitCode(s.GetText())))); }
private static void PasteReplCode(PythonReplEvaluator eval, string pasting) { // there's some text in the buffer... var view = eval.Window.TextView; var caret = view.Caret; if (view.Selection.IsActive && !view.Selection.IsEmpty) { foreach (var span in view.Selection.SelectedSpans) { foreach (var normalizedSpan in view.BufferGraph.MapDownToBuffer(span, SpanTrackingMode.EdgeInclusive, eval.Window.CurrentLanguageBuffer)) { normalizedSpan.Snapshot.TextBuffer.Delete(normalizedSpan); } } } var curBuffer = eval.Window.CurrentLanguageBuffer; var inputPoint = view.BufferGraph.MapDownToBuffer( caret.Position.BufferPosition, PointTrackingMode.Positive, curBuffer, PositionAffinity.Successor ); // if we didn't find a location then see if we're in a prompt, and if so, then we want // to insert after the prompt. if (caret.Position.BufferPosition != eval.Window.TextView.TextBuffer.CurrentSnapshot.Length) { for (int i = caret.Position.BufferPosition + 1; inputPoint == null && i <= eval.Window.TextView.TextBuffer.CurrentSnapshot.Length; i++) { inputPoint = view.BufferGraph.MapDownToBuffer( new SnapshotPoint(eval.Window.TextView.TextBuffer.CurrentSnapshot, i), PointTrackingMode.Positive, curBuffer, PositionAffinity.Successor ); } } if (inputPoint == null) { // we didn't find a point to insert, insert at the beginning. inputPoint = new SnapshotPoint(curBuffer.CurrentSnapshot, 0); } // we want to insert the pasted code at the caret, but we also want to // respect the stepping. So first grab the code before and after the caret. string startText = curBuffer.CurrentSnapshot.GetText(0, inputPoint.Value); string endText = curBuffer.CurrentSnapshot.GetText( inputPoint.Value, curBuffer.CurrentSnapshot.Length - inputPoint.Value); var splitCode = eval.JoinCode(eval.SplitCode(startText + pasting + endText)).ToList(); curBuffer.Delete(new Span(0, curBuffer.CurrentSnapshot.Length)); if (splitCode.Count == 1) { curBuffer.Insert(0, splitCode[0]); var viewPoint = view.BufferGraph.MapUpToBuffer( new SnapshotPoint(curBuffer.CurrentSnapshot, Math.Min(inputPoint.Value.Position + pasting.Length, curBuffer.CurrentSnapshot.Length)), PointTrackingMode.Positive, PositionAffinity.Successor, view.TextBuffer ); if (viewPoint != null) { view.Caret.MoveTo(viewPoint.Value); } } else if (splitCode.Count != 0) { var lastCode = splitCode[splitCode.Count - 1]; splitCode.RemoveAt(splitCode.Count - 1); eval.Window.ReadyForInput += new PendLastSplitCode(eval.Window, lastCode).AppendCode; eval.Window.Submit(splitCode); } else { eval.Window.CurrentLanguageBuffer.Insert(0, startText + pasting + endText); } }