@@ -303,6 +303,7 @@ HRESULT HwndTerminal::Initialize()
303
303
304
304
_terminal->Create ({ 80 , 25 }, 9001 , *_renderer);
305
305
_terminal->SetWriteInputCallback ([=](std::wstring_view input) noexcept { _WriteTextToConnection (input); });
306
+ _terminal->SetCopyToClipboardCallback ([=](wil::zwstring_view text) noexcept { _CopyTextToSystemClipboard (text, {}, {}); });
306
307
_renderer->EnablePainting ();
307
308
308
309
_multiClickTime = std::chrono::milliseconds{ GetDoubleClickTime () };
321
322
_renderer.reset ();
322
323
_renderEngine.reset ();
323
324
325
+ // These two callbacks have a dangling reference to `this`; let's just clear them
326
+ _terminal->SetWriteInputCallback (nullptr );
327
+ _terminal->SetCopyToClipboardCallback (nullptr );
328
+
324
329
if (auto localHwnd{ _hwnd.release () })
325
330
{
326
331
// If we're being called through WM_DESTROY, we won't get here (hwnd is already released)
@@ -1043,7 +1048,7 @@ void __stdcall TerminalKillFocus(void* terminal)
1043
1048
// - text - selected text in plain-text format
1044
1049
// - htmlData - selected text in HTML format
1045
1050
// - rtfData - selected text in RTF format
1046
- HRESULT HwndTerminal::_CopyTextToSystemClipboard (const std::wstring& text, const std::string& htmlData, const std::string& rtfData) const
1051
+ HRESULT HwndTerminal::_CopyTextToSystemClipboard (wil::zwstring_view text, wil::zstring_view htmlData, wil::zstring_view rtfData) const
1047
1052
try
1048
1053
{
1049
1054
RETURN_HR_IF_NULL (E_NOT_VALID_STATE, _terminal);
@@ -1099,7 +1104,7 @@ CATCH_RETURN()
1099
1104
// Arguments:
1100
1105
// - stringToCopy - The string to copy
1101
1106
// - lpszFormat - the name of the format
1102
- HRESULT HwndTerminal::_CopyToSystemClipboard(const std::string& stringToCopy, LPCWSTR lpszFormat) const
1107
+ HRESULT HwndTerminal::_CopyToSystemClipboard(wil::zstring_view stringToCopy, LPCWSTR lpszFormat) const
1103
1108
{
1104
1109
const auto cbData = stringToCopy.size () + 1 ; // +1 for '\0'
1105
1110
if (cbData)
0 commit comments