public static JumpLabelUserControl GetFreeUserControl()
        {
            JumpLabelUserControl ctrl = null;

            if (1 > cache.Count)
            {
                ctrl = new JumpLabelUserControl();
            }
            else
            {
                ctrl = cache.Pop();
            }
            return(ctrl);
        }
 public Jump(
     SnapshotSpan span,
     string label,
     JumpLabelUserControl labelAdornment,
     IVsWindowFrame windowFrame,
     IVsTextView windowPrimaryTextView,
     string vanillaTabCaption
     )
 {
     this.span                  = span;
     this.label                 = label;
     this.labelAdornment        = labelAdornment;
     this.windowFrame           = windowFrame;
     this.windowPrimaryTextView = windowPrimaryTextView;
     this.vanillaTabCaption     = vanillaTabCaption;
 }
Esempio n. 3
0
        public void Init()
        {
            {
                var A = new EditorHostFactory();
                var B = A.CreateCompositionContainer();
                IEditorFormatMapService efms = B.GetExportedValue <IEditorFormatMapService>();
                if (!VsSettings.IsInitialized)
                {
                    VsSettings.Initialize(this.pkg, efms);
                }
            }

            CreateMenu();
            cmdExec = new CommandExecutorService()
            {
            };
            disableVsVimCmdAvailable = cmdExec.IsCommandAvailable(VsVimSetDisabled);
            enableVsVimCmdAvailable  = cmdExec.IsCommandAvailable(VsVimSetEnabled);
            viEmuPluginPresent       = cmdExec.IsCommandAvailable(ViEmuEnableDisableCommand);
            iVsUiShell  = Package.GetGlobalService(typeof(SVsUIShell)) as IVsUIShell;
            iVsUiShell4 = iVsUiShell as IVsUIShell4;
            JumpLabelUserControl.WarmupCache();
            // warmup options
            GeneralOptions.Instance.caretPositionSensivity = GeneralOptions.Instance.caretPositionSensivity;
            // warmp up:
#if MEASUREEXECTIME
            var watch2_0 = System.Diagnostics.Stopwatch.StartNew();
#endif
            var wfs = iVsUiShell.GetDocumentWindowFrames().GetValueOrDefault();
            if (wfs.Count > 0)
            {
                Trace.WriteLine("GetDocumentWindowFrames warmed up");
                foreach (var wf in wfs)
                {
                    wf.GetProperty((int)VsFramePropID.Caption, out var oce);
                    wf.SetProperty((int)VsFramePropID.Caption, (string)oce);
                }
            }
#if MEASUREEXECTIME
            watch2_0.Stop();
            Trace.WriteLine($"PeasyMotion Adornment warmup document tabs: {watch2_0.ElapsedMilliseconds} ms");
#endif
        }
 public void JumpLabelAdornmentRemovedCallback(object _, UIElement element)
 {
     JumpLabelUserControl.ReleaseUserControl(element as JumpLabelUserControl);
 }
        private Dictionary <char, JumpNode> computeGroups(int wordStartIndex, int wordEndIndex, string keys0, string prefix, List <JumpWord> jumpWords)
        {
            // SC-Tree algorithm from vim-easymotion script with minor changes
            var wordCount = wordEndIndex - wordStartIndex + 1;
            var keyCount  = keys0.Length;

            Dictionary <char, JumpNode> groups = new Dictionary <char, JumpNode>();

            var keys = keys0; //Reverse(keys0);

            var keyCounts     = new int[keyCount];
            var keyCountsKeys = new Dictionary <char, int>(keyCount);
            var j             = 0;

            foreach (char key in keys)
            {
                keyCounts[j]       = 0;
                keyCountsKeys[key] = j;
                j++;
            }

            var targetsLeft = wordCount;
            var level       = 0;
            var i           = 0;

            while (targetsLeft > 0)
            {
                var childrenCount = level == 0 ? 1 : keyCount - 1;
                foreach (char key in keys)
                {
                    keyCounts[keyCountsKeys[key]] += childrenCount;
                    targetsLeft -= childrenCount;
                    if (targetsLeft <= 0)
                    {
                        keyCounts[keyCountsKeys[key]] += targetsLeft;
                        break;
                    }
                    i += 1;
                }
                level += 1;
            }

            var k        = 0;
            var keyIndex = 0;

            Array.Reverse(keyCounts);
            foreach (int KeyCount2 in keyCounts)
            {
                if (KeyCount2 > 1)
                {
                    groups[keys[keyIndex]] = new JumpNode()
                    {
                        jumpWordIndex = -1,
                        childrenNodes = computeGroups(wordStartIndex + k, wordStartIndex + k + KeyCount2 - 1, Reverse(string.Copy(keys)),
                                                      prefix + keys[keyIndex], jumpWords)
                    };
                }
                else if (KeyCount2 == 1)
                {
                    groups[keys[keyIndex]] = new JumpNode()
                    {
                        jumpWordIndex = wordStartIndex + k,
                        childrenNodes = null
                    };
                    var    jw        = jumpWords[wordStartIndex + k];
                    string jumpLabel = prefix + keys[keyIndex];

                    JumpLabelUserControl adornment = null;
                    if (jw.windowFrame == null)  // winframe=null => regular textview navigation.
                    {
#if MEASUREEXECTIME
                        if (createAdornmentUIElem == null)
                        {
                            createAdornmentUIElem = Stopwatch.StartNew();
                        }
                        else
                        {
                            createAdornmentUIElem.Start();
                        }
#endif
                        adornment = JumpLabelUserControl.GetFreeUserControl();
                        adornment.setup(jumpLabel, jw.adornmentBounds, this.jumpLabelCachedSetupParams);

#if MEASUREEXECTIME
                        createAdornmentUIElem.Stop();
#endif

#if MEASUREEXECTIME
                        if (adornmentCreateStopwatch == null)
                        {
                            adornmentCreateStopwatch = Stopwatch.StartNew();
                        }
                        else
                        {
                            adornmentCreateStopwatch.Start();
                        }
#endif
                        //TraceLine("before AddAdornment");
                        this.layer.AddAdornment(AdornmentPositioningBehavior.TextRelative, jw.span, null, adornment, JumpLabelAdornmentRemovedCallback);
#if DEBUG_LABEL_ALGO
                        Trace.WriteLine($"POS={jw.textViewPosDbg,5} Adding jumplabel adornment");
#endif

#if MEASUREEXECTIME
                        adornmentCreateStopwatch.Stop();
#endif
                    }

                    //Debug.WriteLine(jw.text + " -> |" + jumpLabel + "|");
                    var cj = new Jump(
                        span: jw.span,
                        label: jumpLabel,
                        labelAdornment: adornment,
                        windowFrame: jw.windowFrame,
                        vanillaTabCaption: jw.vanillaTabCaption,
                        windowPrimaryTextView: jw.windowPrimaryTextView
                        );
                    currentJumps.Add(cj);
                }
                else
                {
                    continue;
                }
                keyIndex += 1;
                k        += KeyCount2;
            }

            return(groups);
        }
 public static void ReleaseUserControl(JumpLabelUserControl ctrl)
 {
     cache.Push(ctrl);
 }