Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/src/cc/arduino/ConsoleOutputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private void printInConsole(String text) {
if (editorConsole != null) {
SwingUtilities.invokeLater(() -> {
try {
editorConsole.insertString(text, attributes);
editorConsole.insertString(this, text, attributes);
} catch (BadLocationException ble) {
//ignore
}
Expand Down
28 changes: 25 additions & 3 deletions app/src/processing/app/EditorConsole.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public static void setCurrentEditorConsole(EditorConsole console) {

private final DefaultStyledDocument document;
private final JTextPane consoleTextPane;
private int firstErrorOffset = -1;

public EditorConsole() {
document = new DefaultStyledDocument();
Expand Down Expand Up @@ -117,21 +118,42 @@ public void clear() {
// ignore the error otherwise this will cause an infinite loop
// maybe not a good idea in the long run?
}
firstErrorOffset = -1;
}

public void scrollDown() {
getHorizontalScrollBar().setValue(0);
getVerticalScrollBar().setValue(getVerticalScrollBar().getMaximum());
if (firstErrorOffset >= 0) {
try {
// Scroll to the first error, making sure that the line above the error
// is the first one shown.
int offset = Utilities.getPositionAbove(consoleTextPane,
firstErrorOffset, 0);
if (offset < 0)
offset = firstErrorOffset;
Rectangle rect = consoleTextPane.modelToView(offset);
this.getViewport().setViewPosition(new Point(0, rect.y));
} catch (BadLocationException e) {
// Ignore
}
} else {
getHorizontalScrollBar().setValue(0);
getVerticalScrollBar().setValue(getVerticalScrollBar().getMaximum());
}
}

public boolean isEmpty() {
return document.getLength() == 0;
}

public void insertString(String line, SimpleAttributeSet attributes) throws BadLocationException {
public void insertString(ConsoleOutputStream from, String line,
SimpleAttributeSet attributes)
throws BadLocationException {
line = line.replace("\r\n", "\n").replace("\r", "\n");
int offset = document.getLength();
document.insertString(offset, line, attributes);
if (from == err && firstErrorOffset < 0) {
firstErrorOffset = offset;
}
}

public String getText() {
Expand Down