static void RemoveCharBeforeCaret(TextEditorData data) { int offset = data.Caret.Offset; if (offset <= 0) { return; } var version = data.Version; var o = data.Caret.Offset; if (CaretMoveActions.IsLowSurrogateMarkerSet(data.GetCharAt(offset - 1))) { data.Remove(offset - 2, 2); } else { data.Remove(offset - 1, 1); } data.Caret.Location = data.OffsetToLocation(version.MoveOffsetTo(data.Version, offset)); }
public SnapshotSpan GetTextElementSpan(SnapshotPoint bufferPosition) { bufferPosition = this.FixBufferPosition(bufferPosition); if (!this.ContainsBufferPosition(bufferPosition)) { throw new ArgumentOutOfRangeException(nameof(bufferPosition)); } if (bufferPosition >= ExtentIncludingLineBreak.End - LineBreakLength) { return(new SnapshotSpan(ExtentIncludingLineBreak.End - LineBreakLength, LineBreakLength)); } var line = textEditor.GetLineByOffset(bufferPosition.Position); var lineOffset = line.Offset; var highlightedLine = this.textEditor.Document.SyntaxMode.GetHighlightedLineAsync(line, default(CancellationToken)).WaitAndGetResult(); if (highlightedLine != null) { foreach (var seg in highlightedLine.Segments) { if (seg.Contains(bufferPosition - lineOffset)) { return(new SnapshotSpan(bufferPosition.Snapshot, lineOffset + seg.Offset, seg.Length)); } } } var c = textEditor.GetCharAt(bufferPosition.Position); if (CaretMoveActions.IsLowSurrogateMarkerSet(c)) { return(new SnapshotSpan(bufferPosition.Snapshot, bufferPosition.Position, 2)); } if (CaretMoveActions.IsHighSurrogateMarkerSet(c)) { return(new SnapshotSpan(bufferPosition.Snapshot, bufferPosition.Position - 1, 2)); } return(new SnapshotSpan(bufferPosition, 1)); }