/// <summary>
        /// Initializes a new instance of the <see cref="PeasyMotionEdAdornment"/> class.
        /// </summary>
        /// <param name="view">Text view to create the adornment for</param>
        public PeasyMotionEdAdornment(PeasyMotionEdAdornmentCtorArgs args)
        {
            this.jumpLabelKeyArray = GeneralOptions.Instance.AllowedJumpKeys;
#if MEASUREEXECTIME
            var watch0 = System.Diagnostics.Stopwatch.StartNew();
#endif
            jumpMode = args.jumpMode;

            var jumpLabelAssignmentAlgorithm = GeneralOptions.Instance.getJumpLabelAssignmentAlgorithm();
            var caretPositionSensivity       = Math.Min(Int32.MaxValue >> 2, Math.Abs(GeneralOptions.Instance.caretPositionSensivity));


            this.textStructureNavigator = args.textStructNav;

            this.vsTextView = args.vsTextView;
            this.view       = args.wpfView;

            this.layer = view.GetAdornmentLayer("PeasyMotionEdAdornment");
            //this.view.LayoutChanged += this.OnLayoutChanged;

            this.vsSettings = VsSettings.GetOrCreate(view);
            // subscribe to fmt updates, so user can tune color faster if PeasyMotion was invoked
            this.vsSettings.PropertyChanged += this.OnFormattingPropertyChanged;

            this.jumpLabelCachedSetupParams.fontRenderingEmSize = this.view.FormattedLineSource.DefaultTextProperties.FontRenderingEmSize;
            this.jumpLabelCachedSetupParams.typeface            = this.view.FormattedLineSource.DefaultTextProperties.Typeface;
            this.jumpLabelCachedSetupParams.labelFg             = this.vsSettings.JumpLabelFirstMotionForegroundColor;
            this.jumpLabelCachedSetupParams.labelBg             = this.vsSettings.JumpLabelFirstMotionBackgroundColor;
            this.jumpLabelCachedSetupParams.labelFinalMotionFg  = this.vsSettings.JumpLabelFinalMotionForegroundColor;
            this.jumpLabelCachedSetupParams.labelFinalMotionBg  = this.vsSettings.JumpLabelFinalMotionBackgroundColor;
            this.jumpLabelCachedSetupParams.Freeze();

            var jumpWords = new List <JumpWord>();
#if MEASUREEXECTIME
            watch0.Stop();
            Trace.WriteLine($"PeasyMotion Adornment ctor settings, members init, etc: {watch0.ElapsedMilliseconds} ms");
#endif


            if (jumpMode == JumpMode.VisibleDocuments)
            {
                SetupJumpToDocumentTabMode(jumpWords);
            }
            else
            {
                SetupJumpInsideTextViewMode(jumpWords, jumpLabelAssignmentAlgorithm, caretPositionSensivity, args.twoCharSearchJumpKeys);
            }

            if (JumpLabelAssignmentAlgorithm.CaretRelative == jumpLabelAssignmentAlgorithm)
            {
#if MEASUREEXECTIME
                var watch2 = System.Diagnostics.Stopwatch.StartNew();
#endif
                // sort jump words from closest to cursor to farthest
                jumpWords.Sort((a, b) => + a.distanceToCursor.CompareTo(b.distanceToCursor));
#if MEASUREEXECTIME
                watch2.Stop();
                Trace.WriteLine($"PeasyMotion Adornment sort words: {watch2.ElapsedMilliseconds} ms");
#endif
            }

#if MEASUREEXECTIME
            var watch3 = System.Diagnostics.Stopwatch.StartNew();
#endif
            _ = computeGroups(0, jumpWords.Count - 1, (jumpLabelKeyArray), "", jumpWords);

#if MEASUREEXECTIME
            watch3.Stop();
            Trace.WriteLine($"PeasyMotion Adornments group&create: {watch3?.ElapsedMilliseconds} ms");
#endif

#if MEASUREEXECTIME
            Trace.WriteLine($"PeasyMotion Adornments create: {adornmentCreateStopwatch?.ElapsedMilliseconds} ms");
            Trace.WriteLine($"PeasyMotion Adornments UI Elem create: {createAdornmentUIElem?.ElapsedMilliseconds} ms");
            Trace.WriteLine($"PeasyMotion Adornment total jump labels - {jumpWords?.Count}");
            createAdornmentUIElem    = null;
            adornmentCreateStopwatch = null;
#endif

            if (jumpMode == JumpMode.VisibleDocuments)
            {
                SetupJumpToDocumentTabFinalPhase();
            }
        }
예제 #2
0
        private void ExecuteCommonJumpCode()
        {
            ShowNotificationsIfAny();

            #if MEASUREEXECTIME
            var watch = System.Diagnostics.Stopwatch.StartNew();
            #endif
            textMgr.GetActiveView(1, null, out IVsTextView vsTextView);
            if (vsTextView == null)
            {
                Debug.Fail("MenuItemCallback: could not retrieve current view");
                return;
            }
            IWpfTextView wpfTextView = editor.GetWpfTextView(vsTextView);
            if (wpfTextView == null)
            {
                Debug.Fail("failed to retrieve current view");
                return;
            }

            #if MEASUREEXECTIME
            var watch3 = System.Diagnostics.Stopwatch.StartNew();
            #endif
            if (adornmentMgr != null)
            {
                Deactivate();
            }

            #if MEASUREEXECTIME
            watch3.Stop();
            Trace.WriteLine($"PeasyMotion Deactivate(): {watch3.ElapsedMilliseconds} ms");
            #endif

            #if MEASUREEXECTIME
            var watch2 = System.Diagnostics.Stopwatch.StartNew();
            #endif
            TryDisableVsVim();
            #if MEASUREEXECTIME
            watch2.Stop();
            Trace.WriteLine($"PeasyMotion TryDisableVsVim: {watch2.ElapsedMilliseconds} ms");
            #endif

            #if MEASUREEXECTIME
            var watch7 = System.Diagnostics.Stopwatch.StartNew();
            #endif
            TryDisableViEmu();
            #if MEASUREEXECTIME
            watch7.Stop();
            Trace.WriteLine($"PeasyMotion TryDisableViEmu: {watch7.ElapsedMilliseconds} ms");
            #endif

            ITextStructureNavigator textStructNav = this.textStructureNavigatorSelector.GetTextStructureNavigator(wpfTextView.TextBuffer);

            var args = new PeasyMotionEdAdornmentCtorArgs {
                vsTextView            = vsTextView,
                wpfView               = wpfTextView,
                textStructNav         = textStructNav,
                jumpMode              = activeJumpMode,
                twoCharSearchJumpKeys = this.userQueryAccumulatedKeyChars?.ToLowerInvariant()
            };
            adornmentMgr = new PeasyMotionEdAdornment(args);

            ThreadHelper.ThrowIfNotOnUIThread();
            CreateInputListener(vsTextView, wpfTextView);
            wpfTextView.LostAggregateFocus += OnTextViewFocusLost;

            #if MEASUREEXECTIME
            watch.Stop();
            Trace.WriteLine($"PeasyMotion FullExecTime: {watch.ElapsedMilliseconds} ms");
            #endif

            if (!adornmentMgr.anyJumpsAvailable())   // empty text? no jump labels
            {
                Deactivate();
            }
        }