Skip to content

Commit 6b5b6df

Browse files
committed
feat: Add toggle poptip and fix lsp frame bug
1 parent a38265f commit 6b5b6df

File tree

1 file changed

+27
-17
lines changed

1 file changed

+27
-17
lines changed

jcs-poptip.el

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -274,11 +274,16 @@ forever delay. HEIGHT of the tooltip that will display."
274274

275275
(defun jcs-poptip--lsp-pre (&rest _)
276276
"Post command for LSP doc."
277-
(unless (memq this-command '( handle-switch-frame
278-
lsp-ui-doc--tooltip-mouse-motion
279-
dap-tooltip-mouse-motion))
280-
(unless (memq this-command '( jcs-poptip-focus jcs-poptip-focus-frame))
281-
(lsp-ui-doc--hide-frame))
277+
(when (and (not (frame-parent))
278+
(not (memq this-command '( handle-switch-frame
279+
ignore-preserving-kill-region
280+
lsp-ui-doc--tooltip-mouse-motion
281+
dap-tooltip-mouse-motion
282+
;; Avoid re-enter.
283+
jcs-poptip-focus
284+
jcs-poptip-focus-frame
285+
jcs-poptip-toggle-focus))))
286+
(lsp-ui-doc--hide-frame)
282287
(remove-hook 'pre-command-hook #'jcs-poptip--lsp-pre)))
283288

284289
;;
@@ -296,24 +301,29 @@ forever delay. HEIGHT of the tooltip that will display."
296301
"Unfocus poptip."
297302
(interactive)
298303
(ignore-errors (jcs-poptip-unfocus-frame))
299-
(ignore-errors (lsp-ui-doc-unfocus-frame))
300-
(add-hook 'pre-command-hook #'jcs-poptip--lsp-pre))
304+
(ignore-errors (lsp-ui-doc-unfocus-frame)))
305+
306+
;;;###autoload
307+
(defun jcs-poptip-toggle-focus ()
308+
"Unfocus poptip."
309+
(interactive)
310+
(if (frame-parent) (jcs-poptip-unfocus) (jcs-poptip-focus)))
301311

302312
;;;###autoload
303313
(defun jcs-poptip ()
304314
"Show current symbol info."
305315
(interactive)
306316
(company-abort)
307-
(if (bound-and-true-p lsp-managed-mode) ; if lsp is connected
308-
(or (ignore-errors (call-interactively #'lsp-ui-doc-glance))
309-
(ignore-errors (call-interactively #'lsp-ui-doc-show)))
310-
(cond ((ignore-errors (jcs-poptip--describe-it)))
311-
((or (ignore-errors (jcs-poptip--company-dict))
312-
(ignore-errors (jcs-poptip--company-doc))))
313-
((ignore-errors (preview-it)))
314-
(t (define-it-at-point)))
315-
;; In case we are using region, cancel the select region.
316-
(deactivate-mark)))
317+
(cond ((bound-and-true-p lsp-managed-mode)
318+
(ignore-errors (call-interactively #'lsp-ui-doc-show))
319+
(add-hook 'pre-command-hook #'jcs-poptip--lsp-pre))
320+
((ignore-errors (jcs-poptip--describe-it)))
321+
((or (ignore-errors (jcs-poptip--company-dict))
322+
(ignore-errors (jcs-poptip--company-doc))))
323+
((ignore-errors (preview-it)))
324+
(t (define-it-at-point)))
325+
;; In case we are using region, cancel the select region.
326+
(deactivate-mark))
317327

318328
(provide 'jcs-poptip)
319329
;;; jcs-poptip.el ends here

0 commit comments

Comments
 (0)