@@ -1187,6 +1187,16 @@ public void select(int start, int end)
1187
1187
selectionEndLine = newEndLine ;
1188
1188
biasLeft = newBias ;
1189
1189
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
+
1190
1200
fireCaretEvent ();
1191
1201
}
1192
1202
@@ -1649,7 +1659,11 @@ public void copy()
1649
1659
for (int i = 0 ; i < repeatCount ; i ++)
1650
1660
buf .append (selection );
1651
1661
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 );
1653
1667
}
1654
1668
}
1655
1669
@@ -2206,6 +2220,25 @@ public void mousePressed(MouseEvent evt)
2206
2220
return ;
2207
2221
}
2208
2222
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
+
2209
2242
int line = yToLine (evt .getY ());
2210
2243
int offset = xToOffset (line ,evt .getX ());
2211
2244
int dot = getLineStartOffset (line ) + offset ;
0 commit comments