Skip to content

Commit

Permalink
Support select-paste on Linux (Paul Stoffregen)
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulStoffregen committed Apr 22, 2013
1 parent a138309 commit d66930f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
35 changes: 34 additions & 1 deletion app/src/processing/app/syntax/JEditTextArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -1187,6 +1187,16 @@ public void select(int start, int end)
selectionEndLine = newEndLine;
biasLeft = newBias;

if (newStart != newEnd) {
Clipboard unixclipboard = getToolkit().getSystemSelection();
if (unixclipboard != null) {
String selection = getSelectedText();
if (selection != null) {
unixclipboard.setContents(new StringSelection(selection), null);
}
}
}

fireCaretEvent();
}

Expand Down Expand Up @@ -1649,7 +1659,11 @@ public void copy()
for(int i = 0; i < repeatCount; i++)
buf.append(selection);

clipboard.setContents(new StringSelection(buf.toString()),null);
Transferable t = new StringSelection(buf.toString());
clipboard.setContents(t, null);

Clipboard unixclipboard = getToolkit().getSystemSelection();
if (unixclipboard != null) unixclipboard.setContents(t, null);
}
}

Expand Down Expand Up @@ -2206,6 +2220,25 @@ public void mousePressed(MouseEvent evt)
return;
}

// on Linux, middle button pastes selected text
if ((evt.getModifiers() & InputEvent.BUTTON2_MASK) != 0) {
Clipboard unixclipboard = getToolkit().getSystemSelection();
if (unixclipboard != null) {
Transferable t = unixclipboard.getContents(null);
if (t != null && t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
try {
String s = (String)t.getTransferData(DataFlavor.stringFlavor);
s = s.replace('\u00A0', ' ');
if (editable) setSelectedText(s);
} catch (Exception e) {
System.err.println(e);
e.printStackTrace();
}
}
return;
}
}

int line = yToLine(evt.getY());
int offset = xToOffset(line,evt.getX());
int dot = getLineStartOffset(line) + offset;
Expand Down
2 changes: 2 additions & 0 deletions app/src/processing/app/tools/DiscourseFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ public void lostOwnership(Clipboard clipboard, Transferable contents) {
// i don't care about ownership
}
});
Clipboard unixclipboard = Toolkit.getDefaultToolkit().getSystemSelection();
if (unixclipboard != null) unixclipboard.setContents(formatted, null);

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

0 comments on commit d66930f

Please sign in to comment.