From e22463032ff9e7cb7ab32c92a1c7428869ce8d58 Mon Sep 17 00:00:00 2001 From: Federico Fissore Date: Mon, 6 Jul 2015 09:52:40 +0200 Subject: [PATCH] Editor: triple click select whole line, new line included. Fixes #3469 --- .../app/syntax/SketchTextAreaEditorKit.java | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/app/src/processing/app/syntax/SketchTextAreaEditorKit.java b/app/src/processing/app/syntax/SketchTextAreaEditorKit.java index b31bfcb2e..b1c03e960 100644 --- a/app/src/processing/app/syntax/SketchTextAreaEditorKit.java +++ b/app/src/processing/app/syntax/SketchTextAreaEditorKit.java @@ -15,7 +15,8 @@ public class SketchTextAreaEditorKit extends RSyntaxTextAreaEditorKit { private static final Action[] defaultActions = { new DeleteNextWordAction(), - new DeleteLineToCursorAction() + new DeleteLineToCursorAction(), + new SelectWholeLineAction() }; @Override @@ -100,4 +101,29 @@ public class SketchTextAreaEditorKit extends RSyntaxTextAreaEditorKit { } + /** + * Selects the line around the caret. + */ + public static class SelectWholeLineAction extends RecordableTextAction { + + public SelectWholeLineAction() { + super(selectLineAction); + } + + @Override + public void actionPerformedImpl(ActionEvent e, RTextArea textArea) { + Document document = textArea.getDocument(); + Element map = document.getDefaultRootElement(); + int currentLineNum = map.getElementIndex(textArea.getCaretPosition()); + Element currentLineElement = map.getElement(currentLineNum); + textArea.select(currentLineElement.getStartOffset(), currentLineElement.getEndOffset()); + } + + @Override + public final String getMacroID() { + return DefaultEditorKit.selectLineAction; + } + + } + }