From 0ea379e5977e1a786431c5a714c077b8fc438584 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Urba=C5=84ski?= Date: Sun, 10 May 2020 21:22:53 +0200 Subject: [PATCH] Added selectLine method and copying whole line when no selection is made --- .../processing/app/syntax/JEditTextArea.java | 43 ++++++++++++------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/app/src/processing/app/syntax/JEditTextArea.java b/app/src/processing/app/syntax/JEditTextArea.java index 8554078f4f..fd3e2c861f 100644 --- a/app/src/processing/app/syntax/JEditTextArea.java +++ b/app/src/processing/app/syntax/JEditTextArea.java @@ -1212,6 +1212,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. */ @@ -1635,6 +1649,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) { @@ -1646,20 +1661,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(); - StringBuilder sb = new StringBuilder(); - for(int i = 0; i < repeatCount; i++) - sb.append(selection); - - clipboard.setContents(new StringSelection(sb.toString()), 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); } } @@ -2530,10 +2546,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); } }