1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-01-17 06:52:18 +01:00

Support select-paste on Linux (Paul Stoffregen)

This commit is contained in:
PaulStoffregen 2013-04-22 04:22:21 -07:00
parent a138309ff6
commit d66930fd6a
2 changed files with 36 additions and 1 deletions

View File

@ -1187,6 +1187,16 @@ public class JEditTextArea extends JComponent
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();
}
@ -1649,7 +1659,11 @@ public class JEditTextArea extends JComponent
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);
}
}
@ -2206,6 +2220,25 @@ public class JEditTextArea extends JComponent
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;

View File

@ -108,6 +108,8 @@ public class DiscourseFormat {
// 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 ") +