public static SingleSelection Create(int start, int end, SingleSelection directionProvider) { var span = directionProvider.selection.TextBuffer.CurrentSnapshot .CreateTrackingSpan(start, end - start, SpanTrackingMode.EdgeInclusive); return(new SingleSelection(span, directionProvider.isReversed)); }
public SingleSelectionWithLocation(int caret, int start, int end, SingleSelection selection) { this.Caret = caret; this.Start = start; this.End = end; this.Selection = selection; this.IsZeroLength = this.Start == this.End; }
protected override void Search( MultiCaretCommandFilter commandFilter, SelectionList targetSelections, SingleSelection firstText, SnapshotSpan lastText, FindData findData) { targetSelections.InsertExpectEnd( commandFilter.textSearch.FindAll(findData).ToSingleSelections(false)); }
public static IEnumerable <SingleSelection> ToSingleSelections( this IEnumerable <SnapshotSpan> spans, bool areReversed) { foreach (var span in spans) { var selection = SingleSelection.Create(span, areReversed); if (selection.HasValue) { yield return(selection.Value); } } }
private static int SplitSelectionIntoLines( MultiCaretCommandFilter commandFilter, ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut) { commandFilter.SelectionSwapExec( (currentSelections, targetSelections) => { foreach (var selection in currentSelections) { var span = selection.GetSelectionSpan(); var searchingStart = true; SingleSelection?previous = null; foreach (var line in commandFilter.textView.TextBuffer.CurrentSnapshot.Lines) { var intersection = line.Extent.Intersection(span); if (intersection.HasValue) { if (previous.HasValue) { targetSelections.InsertExpectEnd(previous.Value); previous = null; } searchingStart = false; var newSelection = SingleSelection.Create(intersection.Value, false); if (newSelection.HasValue) { if (intersection.Value.Length != 0) { targetSelections.InsertExpectEnd(newSelection.Value); } else { previous = newSelection; } } } else if (!searchingStart) { break; } } } }); return(VSConstants.S_OK); }
protected override void Search( MultiCaretCommandFilter commandFilter, SelectionList targetSelections, SingleSelection firstText, SnapshotSpan lastText, FindData findData) { SearchOne( commandFilter, firstText.GetSelectionSpan().Start.Position, o => o.Start.Position, targetSelections.InsertExpectStart, findData); }
private static int HandleTypeChar( MultiCaretCommandFilter commandFilter, ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut) { var typed = ((char)Marshal.GetObjectForNativeVariant <ushort>(pvaIn)).ToString(); commandFilter.SelectionSwapExec( (tempSelections, targetSelections) => { using (var edit = commandFilter.CreateEdit()) { foreach (var selection in tempSelections) { edit.Replace(selection.GetSelectionSpan().Span, typed); } edit.Apply(); } // Whatever we typed the tracking spans should now end at the // end of our typing which is where our carets should be foreach (var selection in tempSelections) { var newSelection = SingleSelection.Create( commandFilter.textView.TextSnapshot, selection.GetSelectionSpan().Span.End, false); if (newSelection.HasValue) { targetSelections.InsertExpectEnd(newSelection.Value); } } }); return(VSConstants.S_OK); }
protected static void SearchOne( MultiCaretCommandFilter commandFilter, int startIndex, Func <SnapshotSpan, int> getSearchStart, Func <SingleSelection, bool> insert, FindData findData) { // Look for the next selection - if the exact same selection already exists then // we need to keep looking until we get back to the beginning. var searchStart = startIndex; while (true) { var next = commandFilter.textSearch.FindNext(searchStart, true, findData); if (!next.HasValue) { return; } // If we have looped round then break out searchStart = getSearchStart(next.Value); if (searchStart == startIndex) { return; } var selection = SingleSelection.Create(next.Value, false); if (!selection.HasValue) { return; } // If we manage to insert then we are done if (insert(selection.Value)) { return; } } }
protected abstract void Search( MultiCaretCommandFilter commandFilter, SelectionList targetSelections, SingleSelection firstText, SnapshotSpan lastText, FindData findData);
public SingleSelection WithDirection(SingleSelection directionProvider) => new SingleSelection(this.selection, directionProvider.isReversed);
public SingleSelection ExpandTo(int start, int end) => SingleSelection.Create(Math.Min(this.Start, start), Math.Max(this.End, end), this.Selection);