Skip to content

Commit d66930f

Browse files
Support select-paste on Linux (Paul Stoffregen)
1 parent a138309 commit d66930f

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

app/src/processing/app/syntax/JEditTextArea.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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;

app/src/processing/app/tools/DiscourseFormat.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ public void lostOwnership(Clipboard clipboard, Transferable contents) {
108108
// i don't care about ownership
109109
}
110110
});
111+
Clipboard unixclipboard = Toolkit.getDefaultToolkit().getSystemSelection();
112+
if (unixclipboard != null) unixclipboard.setContents(formatted, null);
111113

112114
editor.statusNotice("Code formatted for " +
113115
(html ? "HTML" : "the Arduino forum ") +

0 commit comments

Comments
 (0)