本文整理汇总了C#中VirtualSnapshotPoint类的典型用法代码示例。如果您正苦于以下问题:C# VirtualSnapshotPoint类的具体用法?C# VirtualSnapshotPoint怎么用?C# VirtualSnapshotPoint使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
VirtualSnapshotPoint类属于命名空间,在下文中一共展示了VirtualSnapshotPoint类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MoveTo
public CaretPosition MoveTo(VirtualSnapshotPoint bufferPosition, PositionAffinity caretAffinity) {
_position = bufferPosition.Position.Position;
return new CaretPosition(bufferPosition,
new MappingPointMock(bufferPosition.Position.Snapshot.TextBuffer, bufferPosition.Position),
PositionAffinity.Successor);
}
示例2: TextCaret
public TextCaret(IWpfTextView textView, IAdornmentLayer caretLayer, ISmartIndentationService smartIndentationService, IClassificationFormatMap classificationFormatMap) {
if (textView == null)
throw new ArgumentNullException(nameof(textView));
if (caretLayer == null)
throw new ArgumentNullException(nameof(caretLayer));
if (smartIndentationService == null)
throw new ArgumentNullException(nameof(smartIndentationService));
if (classificationFormatMap == null)
throw new ArgumentNullException(nameof(classificationFormatMap));
this.textView = textView;
imeState = new ImeState();
this.smartIndentationService = smartIndentationService;
preferredXCoordinate = 0;
__preferredYCoordinate = 0;
Affinity = PositionAffinity.Successor;
currentPosition = new VirtualSnapshotPoint(textView.TextSnapshot, 0);
textView.TextBuffer.ChangedHighPriority += TextBuffer_ChangedHighPriority;
textView.TextBuffer.ContentTypeChanged += TextBuffer_ContentTypeChanged;
textView.Options.OptionChanged += Options_OptionChanged;
textView.VisualElement.AddHandler(UIElement.GotKeyboardFocusEvent, new KeyboardFocusChangedEventHandler(VisualElement_GotKeyboardFocus), true);
textView.VisualElement.AddHandler(UIElement.LostKeyboardFocusEvent, new KeyboardFocusChangedEventHandler(VisualElement_LostKeyboardFocus), true);
textView.LayoutChanged += TextView_LayoutChanged;
textCaretLayer = new TextCaretLayer(this, caretLayer, classificationFormatMap);
InputMethod.SetIsInputMethodSuspended(textView.VisualElement, true);
}
示例3: GetNewCaretPositionSetter
protected override Action GetNewCaretPositionSetter()
{
var currentSnapshot = TextView.TextBuffer.CurrentSnapshot;
var caretPos = TextView.Caret.Position.BufferPosition;
var caretLine = currentSnapshot.GetLineFromPosition(caretPos.Position);
int line = currentSnapshot.GetLineNumberFromPosition(caretPos);
int column = caretPos - caretLine.Start;
// Get start line of scroll bar
var scrollBarLine = TextView.TextViewLines.FirstOrDefault(l => l.VisibilityState != VisibilityState.Hidden);
int scrollBarPos = (scrollBarLine == null) ? 0 : currentSnapshot.GetLineNumberFromPosition(scrollBarLine.Start);
int maxLine = currentSnapshot.LineCount;
Action setNewCaretPosition = () =>
{
var newCurrentSnapshot = TextView.TextBuffer.CurrentSnapshot;
int newMaxLine = newCurrentSnapshot.LineCount;
// Scale caret positions in a linear way
int newLine = (int) ((float)line * (float)newMaxLine / (float)maxLine);
var newCaretPos = newCurrentSnapshot.GetLineFromLineNumber(newLine).Start.Add(column);
var caretPoint = new VirtualSnapshotPoint(newCurrentSnapshot, newCaretPos);
TextView.Caret.MoveTo(caretPoint);
// Assume that the document scales in a linear way
int newScrollBarPos = (int) ((float)scrollBarPos * (float)newMaxLine / (float)maxLine);
TextView.ViewScroller.ScrollViewportVerticallyByLines(ScrollDirection.Down, newScrollBarPos);
};
return setNewCaretPosition;
}
示例4: MouseReferenceInfo
public MouseReferenceInfo(SpanData<ReferenceInfo>? spanData, SpanData<ReferenceInfo>? realSpanData, VirtualSnapshotPoint point) {
SpanData = spanData;
RealSpanData = realSpanData;
virtualSpaces = point.VirtualSpaces;
position = point.Position.Position;
versionNumber = point.Position.Snapshot.Version.VersionNumber;
}
示例5: CreateVisuals
private void CreateVisuals(VirtualSnapshotPoint caretPosition)
{
if ( !settings.CurrentColumnHighlightEnabled ) {
return; // not enabled
}
IWpfTextViewLineCollection textViewLines = view.TextViewLines;
if ( textViewLines == null )
return; // not ready yet.
// make sure the caret position is on the right buffer snapshot
if ( caretPosition.Position.Snapshot != this.view.TextBuffer.CurrentSnapshot )
return;
var line = this.view.GetTextViewLineContainingBufferPosition(
caretPosition.Position
);
var charBounds = line.GetCharacterBounds(caretPosition);
this.columnRect.Width = charBounds.Width;
this.columnRect.Height = this.view.ViewportHeight;
if ( this.columnRect.Height > 2 ) {
this.columnRect.Height -= 2;
}
// Align the image with the top of the bounds of the text geometry
Canvas.SetLeft(this.columnRect, charBounds.Left);
Canvas.SetTop(this.columnRect, this.view.ViewportTop);
layer.AddAdornment(
AdornmentPositioningBehavior.OwnerControlled, null,
CUR_COL_TAG, columnRect, null
);
}
示例6: AddOneOnSameLine1
public void AddOneOnSameLine1()
{
Create("dog cat");
var point = new VirtualSnapshotPoint(_buffer.GetPoint(0));
point = VirtualSnapshotPointUtil.AddOneOnSameLine(point);
Assert.AreEqual(_buffer.GetPoint(1), point.Position);
Assert.IsFalse(point.IsInVirtualSpace);
}
示例7: GetFSharpPos
internal static Range.pos GetFSharpPos(VirtualSnapshotPoint point)
{
var containingLine = point.Position.GetContainingLine();
// F# compiler line numbers start at 1
int lineNumber = containingLine.LineNumber + 1;
int charIndex = point.Position.Position - containingLine.Start.Position;
return Range.mkPos(lineNumber, charIndex);
}
示例8: IsInSelection
bool IsInSelection(VirtualSnapshotPoint point) {
if (wpfTextView.Selection.IsEmpty)
return false;
foreach (var span in wpfTextView.Selection.VirtualSelectedSpans) {
if (span.Contains(point))
return true;
}
return false;
}
示例9: AddOneOnSameLine3
public void AddOneOnSameLine3()
{
Create("dog");
var point = new VirtualSnapshotPoint(_buffer.GetLine(0).EndIncludingLineBreak, 1);
point = VirtualSnapshotPointUtil.AddOneOnSameLine(point);
Assert.AreEqual(_buffer.GetLine(0).EndIncludingLineBreak, point.Position);
Assert.IsTrue(point.IsInVirtualSpace);
Assert.AreEqual(2, point.VirtualSpaces);
}
示例10: MouseLocation
MouseLocation(ITextViewLine textViewLine, VirtualSnapshotPoint position, Point point) {
if (textViewLine == null)
throw new ArgumentNullException(nameof(textViewLine));
TextViewLine = textViewLine;
Position = position;
Affinity = textViewLine.IsLastTextViewLineForSnapshotLine || position.Position != textViewLine.End ? PositionAffinity.Successor : PositionAffinity.Predecessor;
Debug.Assert(position.VirtualSpaces == 0 || Affinity == PositionAffinity.Successor);
Point = point;
}
示例11: MoveCaretToVirtualPoint1
public void MoveCaretToVirtualPoint1()
{
var buffer = EditorUtil.CreateBuffer("foo","bar");
var caret = MockObjectFactory.CreateCaret();
var textView = MockObjectFactory.CreateTextView(buffer:buffer, caret:caret.Object);
var point = new VirtualSnapshotPoint(buffer.GetLine(0), 2);
caret.Setup(x => x.MoveTo(point)).Returns(new CaretPosition()).Verifiable();
caret.Setup(x => x.EnsureVisible()).Verifiable();
TextViewUtil.MoveCaretToVirtualPoint(textView.Object, point);
caret.Verify();
}
示例12: GetFormatted
protected override string GetFormatted(bool isSignatureFile, string source, Fantomas.FormatConfig.FormatConfig config)
{
if (isFormattingCursor)
{
var caretPos = new VirtualSnapshotPoint(TextView.TextBuffer.CurrentSnapshot, TextView.Caret.Position.BufferPosition);
Range.pos pos = TextUtils.GetFSharpPos(caretPos);
return Fantomas.CodeFormatter.formatAroundCursor(isSignatureFile, pos, source, config);
}
Range.pos startPos = TextUtils.GetFSharpPos(TextView.Selection.Start);
Range.pos endPos = TextUtils.GetFSharpPos(TextView.Selection.End);
Range.range range = Range.mkRange("fsfile", startPos, endPos);
return Fantomas.CodeFormatter.formatSelectionFromString(isSignatureFile, range, source, config);
}
示例13: CreateGeometry
public static Geometry CreateGeometry(IWpfTextView textView, VirtualSnapshotSpan span, bool isMultiLine, bool clipToViewport = false) {
var padding = isMultiLine ? LineMarkerPadding : TextMarkerPadding;
var pos = span.Start;
PathGeometry geo = null;
bool createOutlinedPath = false;
while (pos <= span.End) {
var line = textView.GetTextViewLineContainingBufferPosition(pos.Position);
bool useVspaces = line.IsLastDocumentLine();
var lineExtent = new VirtualSnapshotSpan(new VirtualSnapshotPoint(line.Start), new VirtualSnapshotPoint(line.EndIncludingLineBreak, useVspaces ? span.End.VirtualSpaces : 0));
var extentTmp = lineExtent.Intersection(new VirtualSnapshotSpan(pos, span.End));
Debug.Assert(extentTmp != null);
if (line.VisibilityState != VisibilityState.Unattached && extentTmp != null && extentTmp.Value.Length != 0) {
var extent = extentTmp.Value;
Collection<TextBounds> textBounds;
if (extent.Start.IsInVirtualSpace) {
var leading = line.TextRight + extent.Start.VirtualSpaces * textView.FormattedLineSource.ColumnWidth;
double width = line.EndOfLineWidth;
int vspaces = span.End.VirtualSpaces - span.Start.VirtualSpaces;
if (vspaces > 0)
width = vspaces * textView.FormattedLineSource.ColumnWidth;
textBounds = new Collection<TextBounds>();
textBounds.Add(new TextBounds(leading, line.Top, width, line.Height, line.TextTop, line.TextHeight));
}
else if (extent.End.IsInVirtualSpace) {
textBounds = line.GetNormalizedTextBounds(extent.SnapshotSpan);
double width = extent.End.VirtualSpaces * textView.FormattedLineSource.ColumnWidth;
textBounds.Add(new TextBounds(line.TextRight, line.Top, width, line.Height, line.TextTop, line.TextHeight));
}
else
textBounds = line.GetNormalizedTextBounds(extent.SnapshotSpan);
AddGeometries(textView, textBounds, isMultiLine, clipToViewport, padding, SystemParameters.CaretWidth, ref geo, ref createOutlinedPath);
}
if (line.IsLastDocumentLine())
break;
pos = new VirtualSnapshotPoint(line.GetPointAfterLineBreak());
}
if (createOutlinedPath)
geo = geo.GetOutlinedPathGeometry();
if (geo != null && geo.CanFreeze)
geo.Freeze();
return geo;
}
示例14: GetNewCaretPositionSetter
protected override Action GetNewCaretPositionSetter()
{
var caretPos = TextView.Caret.Position.BufferPosition;
if (isFormattingCursor || caretPos == TextView.Selection.Start.Position)
{
int selStartPos = TextView.Selection.Start.Position.Position;
// Get start line of scroll bar
var scrollBarLine = TextView.TextViewLines.FirstOrDefault(l => l.VisibilityState != VisibilityState.Hidden);
int scrollBarPos = (scrollBarLine == null) ? 0 : scrollBarLine.Snapshot.GetLineNumberFromPosition(scrollBarLine.Start);
Action setNewCaretPosition = () =>
{
// The caret is at the start of selection, its position is unchanged
int newSelStartPos = selStartPos;
var newActivePoint = new VirtualSnapshotPoint(TextView.TextBuffer.CurrentSnapshot, newSelStartPos);
TextView.Caret.MoveTo(newActivePoint);
TextView.ViewScroller.ScrollViewportVerticallyByLines(ScrollDirection.Down, scrollBarPos);
};
return setNewCaretPosition;
}
else
{
int selOffsetFromEnd = TextView.TextBuffer.CurrentSnapshot.Length - TextView.Selection.End.Position.Position;
// Get start line of scroll bar
var scrollBarLine = TextView.TextViewLines.FirstOrDefault(l => l.VisibilityState != VisibilityState.Hidden);
int scrollBarPos = (scrollBarLine == null) ? 0 : scrollBarLine.Snapshot.GetLineNumberFromPosition(scrollBarLine.Start);
Action setNewCaretPosition = () =>
{
// The caret is at the end of selection, its offset from the end of text is unchanged
int newSelEndPos = TextView.TextBuffer.CurrentSnapshot.Length - selOffsetFromEnd;
var newAnchorPoint = new VirtualSnapshotPoint(TextView.TextBuffer.CurrentSnapshot, newSelEndPos);
TextView.Caret.MoveTo(newAnchorPoint);
TextView.ViewScroller.ScrollViewportVerticallyByLines(ScrollDirection.Down, scrollBarPos);
};
return setNewCaretPosition;
}
}
示例15: MoveCaretToVirtualPoint
public void MoveCaretToVirtualPoint()
{
var buffer = CreateTextBuffer("foo","bar");
var factory = new MockRepository(MockBehavior.Strict);
var caret = MockObjectFactory.CreateCaret(factory: factory);
caret.Setup(x => x.EnsureVisible()).Verifiable();
var selection = MockObjectFactory.CreateSelection(factory: factory);
selection.Setup(x => x.Clear()).Verifiable();
var textView = MockObjectFactory.CreateTextView(
textBuffer: buffer,
selection: selection.Object,
caret: caret.Object,
factory: factory);
var point = new VirtualSnapshotPoint(buffer.GetLine(0), 2);
caret.Setup(x => x.MoveTo(point)).Returns(new CaretPosition()).Verifiable();
TextViewUtil.MoveCaretToVirtualPoint(textView.Object, point);
factory.Verify();
}