public void TriggerPopup(bool simple, int methodStartPos, string[] data) { try { this.simple = simple; lastMethodStartPos = methodStartPos; base.Popup( form => //on opening { if (!simple) { form.LeftBottomCorner = Npp.GetCurrentDocument().GetCaretScreenLocation(); } else { form.LeftBottomCorner = Cursor.Position; } form.Simple = simple; form.AddData(data); KeyInterceptor.Instance.Add(Keys.Escape); KeyInterceptor.Instance.KeyDown += Instance_KeyDown; if (!simple) { KeyInterceptor.Instance.Add(Keys.Down, Keys.Up, Keys.Escape, Keys.Enter, Keys.Delete, Keys.Back); form.KeyPress += (sender, e) => { NppEditor.ProcessKeyPress(e.KeyChar); Plugin.OnCharTyped(e.KeyChar); CheckIfNeedsClosing(); }; form.KeyDown += (sender, e) => { if (e.KeyCode == Keys.Delete) { NppEditor.ProcessDeleteKeyDown(); } }; form.ProcessMethodOverloadHint(NppEditor.GetMethodOverloadHint(methodStartPos)); Task.Factory.StartNew(() => { Rectangle rect = npp.GetClientRect(); while (popupForm != null) { try { Npp.GetCurrentDocument().GrabFocus(); var newRect = npp.GetClientRect(); if (rect != newRect) //if NPP moved, resized close the popup { base.Close(); return; } Thread.Sleep(500); } catch { base.Close(); return; } } }); } }, form => //on closing { KeyInterceptor.Instance.KeyDown -= Instance_KeyDown; }); } catch { } }