diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index 891f46b77..ef87a6219 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -251,7 +251,7 @@ public class Editor extends JFrame implements RunnerListener { console.setBorder(null); consolePanel.add(console, BorderLayout.CENTER); - lineStatus = new EditorLineStatus(textarea); + lineStatus = new EditorLineStatus(); consolePanel.add(lineStatus, BorderLayout.SOUTH); // RTextScrollPane @@ -957,7 +957,7 @@ public class Editor extends JFrame implements RunnerListener { protected SketchTextArea createTextArea() throws IOException { - SketchTextArea textArea = new SketchTextArea(base.getPdeKeywords()); + final SketchTextArea textArea = new SketchTextArea(base.getPdeKeywords()); textArea.requestFocusInWindow(); textArea.setMarkOccurrences(PreferencesData.getBoolean("editor.advanced")); textArea.setMarginLineEnabled(false); @@ -976,6 +976,17 @@ public class Editor extends JFrame implements RunnerListener { } } }); + textArea.addCaretListener(new CaretListener() { + + @Override + public void caretUpdate(CaretEvent e) { + int lineStart = textArea.getDocument().getDefaultRootElement().getElementIndex(e.getMark()); + int lineEnd = textArea.getDocument().getDefaultRootElement().getElementIndex(e.getDot()); + + lineStatus.set(lineStart, lineEnd); + } + + }); ToolTipManager.sharedInstance().registerComponent(textArea); diff --git a/app/src/processing/app/EditorLineStatus.java b/app/src/processing/app/EditorLineStatus.java index 2acb1eb10..2696d7d41 100644 --- a/app/src/processing/app/EditorLineStatus.java +++ b/app/src/processing/app/EditorLineStatus.java @@ -37,8 +37,6 @@ import processing.app.syntax.SketchTextArea; * Li'l status bar fella that shows the line number. */ public class EditorLineStatus extends JComponent { - SketchTextArea textarea; - int start = -1, stop; Image resize; @@ -55,11 +53,7 @@ public class EditorLineStatus extends JComponent { String serialport = ""; - public EditorLineStatus(SketchTextArea textarea) { - - this.textarea = textarea; - textarea.setEditorLineStatus(this); - + public EditorLineStatus() { background = Theme.getColor("linestatus.bgcolor"); font = Theme.getFont("linestatus.font"); foreground = Theme.getColor("linestatus.color"); diff --git a/app/src/processing/app/syntax/SketchTextArea.java b/app/src/processing/app/syntax/SketchTextArea.java index 08b899916..580fe99f7 100644 --- a/app/src/processing/app/syntax/SketchTextArea.java +++ b/app/src/processing/app/syntax/SketchTextArea.java @@ -76,11 +76,6 @@ public class SketchTextArea extends RSyntaxTextArea { */ private FocusableTip docTooltip; - /** - * The component that tracks the current line number. - */ - protected EditorLineStatus editorLineStatus; - private EditorListener editorListener; private final PdeKeywords pdeKeywords; @@ -168,14 +163,9 @@ public class SketchTextArea extends RSyntaxTextArea { } - public void setEditorLineStatus(EditorLineStatus editorLineStatus) { - this.editorLineStatus = editorLineStatus; - } - @Override public void select(int selectionStart, int selectionEnd) { super.select(selectionStart, selectionEnd); - if (editorLineStatus != null) editorLineStatus.set(selectionStart, selectionEnd); } public boolean isSelectionActive() {