private void ProcessFoundOccurrence(SnapshotSpan occurrence) { if (!Selections.Any(s => s.OverlapsWith(occurrence, Snapshot))) { var start = Snapshot.CreateTrackingPoint(occurrence.Start); var end = Snapshot.CreateTrackingPoint(occurrence.End); var caret = Selections.Last().IsReversed(Snapshot) ? start : end; Selections.Add( new Selection { Start = start, End = end, Caret = caret, ColumnPosition = Snapshot.GetLineColumnFromPosition(caret.GetPoint(Snapshot)) } ); outliningManager.ExpandAll(occurrence, r => r.IsCollapsed); view.Caret.MoveTo(caret == start ? occurrence.Start : occurrence.End); view.ViewScroller.EnsureSpanVisible( new SnapshotSpan(view.Caret.Position.BufferPosition, 0) ); } }
private void UpdateSelection(byte idx) { if (PalSource == null) return; if (ModifierKeys == Keys.Alt) { BackColor = PalSource[idx]; BackColorChanged?.Invoke(this, new EventArgs()); return; } if (!IsSelectable) return; if (IsMultiSelect) { switch (ModifierKeys) { case Keys.Control: if (Selections.Contains(idx)) Selections.Remove(idx); else Selections.Add(idx); break; case Keys.Shift: if (Selections.Count == 0) { Selections.Add(idx); break; } if (Selections.Last() == idx) { Selections.Remove(idx); } else { if (Selections.Last() < idx) { for (int i = Selections.Last() + 1; i <= idx; i++) if (!Selections.Contains((byte)i)) Selections.Add((byte)i); } else { for (int i = Selections.Last() - 1; i >= idx; i--) if (!Selections.Contains((byte)i)) Selections.Add((byte)i); } } break; default: Selections.Clear(); Selections.Add(idx); break; } } else { Selections.Clear(); Selections.Add(idx); } if (PalSource != null) SelectedIndexChanged?.Invoke(this, new EventArgs()); if (IsSelectVisible) Refresh(); }
internal void AddCaretBelow() { foreach (var selection in Selections.ToList()) { view.Caret.MoveTo(selection.GetVirtualPoint(Snapshot)); EditorOperations.MoveLineDown(false); AddCaretMoveToSelections(selection); } view.Caret.MoveTo(Selections.Last().GetVirtualPoint(Snapshot)); }
protected override void ShowMenu(Point coords) { if (ShowTimerMenuEvent != null) { Timer t = null; if (Selections.Count > 0) { TimerTimeNodeObject to = Selections.Last().Drawable as TimerTimeNodeObject; t = to.Timer; } ShowTimerMenuEvent(t, Utils.PosToTime(coords, SecondsPerPixel)); } }
protected override void ShowMenu(Point coords) { if (ShowTimerMenuEvent != null && coords.Y >= PeriodsTimeline.OffsetY && coords.Y <= PeriodsTimeline.OffsetY + PeriodsTimeline.Height) { Timer t = null; if (Selections.Count > 0) { TimerTimeNodeView to = Selections.Last().Drawable as TimerTimeNodeView; t = to.Timer.Model; } ShowTimerMenuEvent(t, VAS.Drawing.Utils.PosToTime(coords, SecondsPerPixel)); } }
/// <summary> /// Handles finding occurrences, selecting and adding to current selections /// </summary> /// <param name="reverseDirection">Search document in reverse direction for an occurrence</param> /// <param name="exactMatch">Search document for an exact match, overrides find-dialog settings</param> internal void SelectNextOccurrence(bool reverseDirection = false, bool exactMatch = false) { // Caret placed on a word, but nothing selected if (!Selections.Any() && view.Selection.IsEmpty) { SelectCurrentWord(view.Caret.Position.BufferPosition); return; } // First selection is selected by user, future selections will be located and selected on command-invocation if (!Selections.Any() && !view.Selection.IsEmpty) { AddCurrentSelectionToSelections(); } // Multiple selections if (Selections.Any()) { // Select words at caret again, this is where we have abandoned selections and goes to carets if (Selections.Any(s => !s.IsSelection())) { var oldSelections = Selections; Selections = new List <Selection>(); foreach (var selection in oldSelections) { if (!selection.IsSelection()) { view.Caret.MoveTo(selection.Caret.GetPoint(Snapshot)); SelectCurrentWord(selection.Caret.GetPoint(Snapshot)); } else { Selections.Add(selection); } } } else { var orderedSelections = HasWrappedDocument ? Selections : Selections.OrderBy(n => n.Caret.GetPosition(Snapshot)).ToList(); var startSelection = reverseDirection && !HasWrappedDocument ? orderedSelections.First() : orderedSelections.Last(); var startIndex = reverseDirection ? startSelection.Start?.GetPosition(Snapshot) ?? startSelection.Caret.GetPosition(Snapshot) : startSelection.End?.GetPosition(Snapshot) ?? startSelection.Caret.GetPosition(Snapshot); var occurrence = textSearchService.FindNext( startIndex, true, GetFindData(reverseDirection, exactMatch) ); if (occurrence.HasValue) { ProcessFoundOccurrence(occurrence.Value); if (!reverseDirection && Selections.Last().Caret.GetPosition(Snapshot) < Selections.First().Caret.GetPosition(Snapshot)) { HasWrappedDocument = true; } if (reverseDirection && Selections.Last().Caret.GetPosition(Snapshot) > Selections.First().Caret.GetPosition(Snapshot)) { HasWrappedDocument = true; } } } view.Selection.Clear(); view.Caret.MoveTo(Selections.Last().Caret.GetPoint(Snapshot)); } }
/// <summary> /// Handles finding occurrences, selecting and adding to current selections /// </summary> /// <param name="reverseDirection">Search document in reverse direction for an occurrence</param> /// <param name="exactMatch">Search document for an exact match, overrides find-dialog settings</param> internal void SelectNextOccurrence(bool reverseDirection = false, bool exactMatch = false) { // Caret placed on a word, but nothing selected if (!Selections.Any() && view.Selection.IsEmpty) { SelectCurrentWord(view.Caret.Position.BufferPosition); return; } // First selection is selected by user, future selections will be located and selected on command-invocation if (!Selections.Any() && !view.Selection.IsEmpty) { AddCurrentSelectionToSelections(); } // Multiple selections if (Selections.Any()) { // Select words at caret again, this is where we have abandoned selections and goes to carets if (Selections.Any(s => !s.IsSelection())) { var oldSelections = Selections; Selections = new List <Selection>(); // Note: The list is in reverse order to fix a bug in EditorOperations.SelectCurrentWord() foreach (var selection in oldSelections.OrderByDescending(n => n.Caret.GetPosition(Snapshot))) { if (!selection.IsSelection()) { view.Caret.MoveTo(selection.Caret.GetPoint(Snapshot)); SelectCurrentWord(selection.Caret.GetPoint(Snapshot)); } else { Selections.Add(selection); } } } else { var orderedSelections = Selections.OrderBy(n => n.Caret.GetPosition(Snapshot)).ToList(); var startIndex = ExtensionOptions.Instance.InwardSelection ^ reverseDirection ? 0 : orderedSelections.Count - 1; var direction = reverseDirection ? -1 : 1; var index = startIndex; do { var position = reverseDirection ? orderedSelections[index].Start.GetPosition(Snapshot) : orderedSelections[index].End.GetPosition(Snapshot); index = (index + direction + orderedSelections.Count) % orderedSelections.Count; if (textSearchService.FindNext(position, true, GetFindData(reverseDirection, exactMatch)) is SnapshotSpan occurrence && !orderedSelections[index].OverlapsWith(occurrence, Snapshot)) { ProcessFoundOccurrence(occurrence); break; } } while (startIndex != index); } view.Selection.Clear(); view.Caret.MoveTo(Selections.Last().Caret.GetPoint(Snapshot)); } }