Example #1
0
		public bool DeleteToEndOfLine() {
			if (!Selection.IsEmpty) {
				var oldSelection = new SavedCaretSelection(this);

				Span deleteSpan;
				if (oldSelection.ActivePoint < oldSelection.AnchorPoint)
					deleteSpan = new Span(oldSelection.ActivePoint.Position, oldSelection.AnchorPoint.Position - oldSelection.ActivePoint.Position);
				else {
					var line = Snapshot.GetLineFromPosition(oldSelection.ActivePoint.Position);
					deleteSpan = new Span(oldSelection.AnchorPoint.Position, line.End.Position - oldSelection.AnchorPoint.Position);
				}

				TextBuffer.Delete(deleteSpan);

				oldSelection.UpdatePositions();
			}
			else {
				var line = Snapshot.GetLineFromPosition(Caret.Position.BufferPosition.Position);
				TextBuffer.Delete(new Span(Caret.Position.BufferPosition.Position, line.End.Position - Caret.Position.BufferPosition.Position));
			}
			return true;
		}
Example #2
0
		public bool DeleteWordToRight() {
			if (Selection.ActivePoint < Selection.AnchorPoint) {
				DeleteSelection();
				return true;
			}

			var selSpan = GetSelectionOrCaretIfNoSelection();
			var wordPoint = GetPointOfRightWord(selSpan.End);

			var oldSelection = new SavedCaretSelection(this);

			var newSelSpan = new VirtualSnapshotSpan(selSpan.Start, new VirtualSnapshotPoint(wordPoint));
			if (Selection.IsEmpty || Selection.Mode != TextSelectionMode.Box)
				TextBuffer.Delete(newSelSpan.SnapshotSpan.Span);
			else {
				var line = Snapshot.GetLineFromPosition(wordPoint.Position);
				int column = wordPoint - line.Start;
				using (var ed = TextBuffer.CreateEdit()) {
					foreach (var span in Selection.SelectedSpans) {
						line = Snapshot.GetLineFromPosition(span.Start.Position);
						var end = line.Start + Math.Min(line.Length, column);
						if (span.Start < end) {
							var newSpan = new SnapshotSpan(span.Start, end);
							ed.Delete(newSpan);
						}
					}
					ed.Apply();
				}
			}

			oldSelection.UpdatePositions();
			return true;
		}
Example #3
0
		public bool DeleteHorizontalWhiteSpace() {
			var oldSelection = new SavedCaretSelection(this);
			var span = Selection.IsEmpty ? GetDefaultHorizontalWhitespaceSpan(Caret.Position.BufferPosition) : Selection.StreamSelectionSpan.SnapshotSpan.Span;

			using (var ed = TextBuffer.CreateEdit()) {
				foreach (var deleteSpan in GetHorizontalWhiteSpaceSpans(Snapshot, span)) {
					Debug.Assert(deleteSpan.Span.Length > 0);
					ed.Delete(deleteSpan.Span);
					if (deleteSpan.AddSpace) {
						// VS always inserts a space character, even if the deleted whitespace chars were all tabs
						ed.Insert(deleteSpan.Span.Start, " ");
					}
				}
				ed.Apply();
			}

			oldSelection.UpdatePositions();
			return true;
		}