예제 #1
0
 internal void CancelSelectNextOccurence()
 {
     if (ExtensionOptions.Instance.KeepFirstEntry)
     {
         view.Caret.MoveTo(Selections.First().Caret.GetPoint(view.TextSnapshot));
     }
     Selections.Clear();
     view.Caret.IsHidden = false;
 }
        DateTimeConvertDialog.Result Command_DateTime_Convert_Dialog()
        {
            if (Selections.Count < 1)
            {
                return(null);
            }

            return(DateTimeConvertDialog.Run(WindowParent, GetString(Selections.First())));
        }
예제 #3
0
        /// <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));
            }
        }