From 7ec2a1f09c6ad1eccd674a78ff5c609f3063a842 Mon Sep 17 00:00:00 2001
From: Jeff Young <jeff@rokeby.ie>
Date: Tue, 12 Mar 2024 17:09:07 +0000
Subject: [PATCH] Allow Scintilla-created clipboard to be accessed after quit.

---
 common/scintilla_tricks.cpp | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/common/scintilla_tricks.cpp b/common/scintilla_tricks.cpp
index 8f107c07d3..f30f869938 100644
--- a/common/scintilla_tricks.cpp
+++ b/common/scintilla_tricks.cpp
@@ -338,10 +338,22 @@ void SCINTILLA_TRICKS::onCharHook( wxKeyEvent& aEvent )
     else if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() == 'X' )
     {
         m_te->Cut();
+
+        if( wxTheClipboard->Open() )
+        {
+            wxTheClipboard->Flush(); // Allow data to be available after closing KiCad
+            wxTheClipboard->Close();
+        }
     }
     else if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() == 'C' )
     {
         m_te->Copy();
+
+        if( wxTheClipboard->Open() )
+        {
+            wxTheClipboard->Flush(); // Allow data to be available after closing KiCad
+            wxTheClipboard->Close();
+        }
     }
     else if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() == 'V' )
     {