diff --git a/app/src/processing/app/syntax/JEditTextArea.java b/app/src/processing/app/syntax/JEditTextArea.java index 312318da0b..b542be2cb7 100644 --- a/app/src/processing/app/syntax/JEditTextArea.java +++ b/app/src/processing/app/syntax/JEditTextArea.java @@ -1240,6 +1240,20 @@ public final void selectAll() select(0,getDocumentLength()); } + /** + * Selects all text in the given line. + * @param line The line number to select all text in it. + */ + public final void selectLine(final int line) + { + selectLine = true; + final int lineStart = getLineStartOffset(line); + final int lineEnd = getLineSelectionStopOffset(line); + select(lineStart, lineEnd); + selectionAncorStart = selectionStart; + selectionAncorEnd = selectionEnd; + } + /** * Moves the mark to the caret position. */ @@ -1663,6 +1677,7 @@ public final void removeCaretListener(CaretListener listener) /** * Deletes the selected text from the text area and places it * into the clipboard. + * If no selection is made, the whole line with caret will be selectd. */ public void cut() { if (editable) { @@ -1674,16 +1689,21 @@ public void cut() { /** * Places the selected text into the clipboard. + * If no selection is made, the whole line with caret will be selectd. */ public void copy() { - if (selectionStart != selectionEnd) { - Clipboard clipboard = getToolkit().getSystemClipboard(); - - String selection = getSelectedText(); - if (selection != null) { - int repeatCount = inputHandler.getRepeatCount(); - clipboard.setContents(new StringSelection(selection.repeat(Math.max(0, repeatCount))), null); + if (selectionStart == selectionEnd) { + selectLine(getCaretLine()); + } + Clipboard clipboard = getToolkit().getSystemClipboard(); + String selection = getSelectedText(); + if (selection != null) { + int repeatCount = inputHandler.getRepeatCount(); + StringBuilder sb = new StringBuilder(); + for(int i = 0; i < repeatCount; i++) { + sb.append(selection); } + clipboard.setContents(new StringSelection(sb.toString()), null); } } @@ -2539,10 +2559,7 @@ private void doDoubleClick(MouseEvent evt, int line, int offset, private void doTripleClick(MouseEvent evt, int line, int offset, int dot) { - selectLine = true; - select(getLineStartOffset(line),getLineSelectionStopOffset(line)); - selectionAncorStart = selectionStart; - selectionAncorEnd = selectionEnd; + selectLine(line); } }