@@ -1187,6 +1187,16 @@ public void select(int start, int end)
11871187 selectionEndLine = newEndLine ;
11881188 biasLeft = newBias ;
11891189
1190+ if (newStart != newEnd ) {
1191+ Clipboard unixclipboard = getToolkit ().getSystemSelection ();
1192+ if (unixclipboard != null ) {
1193+ String selection = getSelectedText ();
1194+ if (selection != null ) {
1195+ unixclipboard .setContents (new StringSelection (selection ), null );
1196+ }
1197+ }
1198+ }
1199+
11901200 fireCaretEvent ();
11911201 }
11921202
@@ -1649,7 +1659,11 @@ public void copy()
16491659 for (int i = 0 ; i < repeatCount ; i ++)
16501660 buf .append (selection );
16511661
1652- clipboard .setContents (new StringSelection (buf .toString ()),null );
1662+ Transferable t = new StringSelection (buf .toString ());
1663+ clipboard .setContents (t , null );
1664+
1665+ Clipboard unixclipboard = getToolkit ().getSystemSelection ();
1666+ if (unixclipboard != null ) unixclipboard .setContents (t , null );
16531667 }
16541668 }
16551669
@@ -2206,6 +2220,25 @@ public void mousePressed(MouseEvent evt)
22062220 return ;
22072221 }
22082222
2223+ // on Linux, middle button pastes selected text
2224+ if ((evt .getModifiers () & InputEvent .BUTTON2_MASK ) != 0 ) {
2225+ Clipboard unixclipboard = getToolkit ().getSystemSelection ();
2226+ if (unixclipboard != null ) {
2227+ Transferable t = unixclipboard .getContents (null );
2228+ if (t != null && t .isDataFlavorSupported (DataFlavor .stringFlavor )) {
2229+ try {
2230+ String s = (String )t .getTransferData (DataFlavor .stringFlavor );
2231+ s = s .replace ('\u00A0' , ' ' );
2232+ if (editable ) setSelectedText (s );
2233+ } catch (Exception e ) {
2234+ System .err .println (e );
2235+ e .printStackTrace ();
2236+ }
2237+ }
2238+ return ;
2239+ }
2240+ }
2241+
22092242 int line = yToLine (evt .getY ());
22102243 int offset = xToOffset (line ,evt .getX ());
22112244 int dot = getLineStartOffset (line ) + offset ;
0 commit comments