1+ import sublime
2+
13from ..libs .view_helpers import *
24from ..libs .text_helpers import escape_html
35from .base_command import TypeScriptBaseTextCommand
@@ -40,6 +42,7 @@ class TypescriptQuickInfoDoc(TypeScriptBaseTextCommand):
4042 def handle_quick_info (self , quick_info_resp_dict , display_point ):
4143 info_str = ""
4244 doc_str = ""
45+ status_info_str = ""
4346
4447 if quick_info_resp_dict ["success" ]:
4548 info_str = self .format_display_parts_html (quick_info_resp_dict ["body" ]["displayParts" ])
@@ -65,14 +68,28 @@ def handle_quick_info(self, quick_info_resp_dict, display_point):
6568 self .view .erase_status ("typescript_info" )
6669
6770 # process tooltips
68- error_html = self .get_error_text_html (display_point )
71+ error_str = self .get_error_text_html (display_point )
72+ error_html = escape_html (error_str )
6973 if TOOLTIP_SUPPORT and (info_str != "" or doc_str != "" or error_html != "" ):
7074 if self .template is None :
7175 self .template = Template (load_quickinfo_and_error_popup_template ())
7276 html = self .get_popup_html (error_html , info_str , doc_str )
7377
78+ def on_navigate (href : str ) -> None :
79+ if href == "copy" :
80+ sublime .set_clipboard ("\n \n " .join (s for s in [error_str , status_info_str ] if s ))
81+ sublime .active_window ().status_message ("TypeScript: info copied to clipboard" )
82+ self .view .hide_popup ()
83+
7484 settings = sublime .load_settings ("TypeScript.sublime-settings" )
75- self .view .show_popup (html , flags = sublime .HIDE_ON_MOUSE_MOVE_AWAY , location = display_point , max_height = 300 , max_width = settings .get ("quick_info_popup_max_width" ) or self .view .viewport_extent ()[0 ])
85+ self .view .show_popup (
86+ html + "<a href=\" copy\" >Copy</a>" ,
87+ flags = sublime .HIDE_ON_MOUSE_MOVE_AWAY ,
88+ location = display_point ,
89+ max_height = 300 ,
90+ max_width = settings .get ("quick_info_popup_max_width" ) or self .view .viewport_extent ()[0 ],
91+ on_navigate = on_navigate ,
92+ )
7693
7794 def get_popup_html (self , error , info , doc ):
7895 theme_styles = get_theme_styles (self .view )
@@ -108,7 +125,7 @@ def get_error_text_html(self, pt):
108125 if region .contains (pt ):
109126 error_text = text
110127 break
111- return escape_html ( error_text )
128+ return error_text
112129
113130 def run (self , text , hover_point = None ):
114131 check_update_view (self .view )
0 commit comments