Skip to content

Commit 3aa81b0

Browse files
Pieter12345cmaglie
authored andcommitted
Add CTRL +/-/scroll shortcuts to adjust editor console font size
Add CTRL +/- and CTRL scroll shortcuts to increase/decrease editor console output text size. This font size is shared with the editor and serial/network monitor. Adjusting the font size on any of these will update them all. Partially fixes #8615.
1 parent 91fc80b commit 3aa81b0

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

app/src/processing/app/Editor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ public void windowDeactivated(WindowEvent e) {
315315
status = new EditorStatus(this);
316316
consolePanel.add(status, BorderLayout.NORTH);
317317

318-
console = new EditorConsole();
318+
console = new EditorConsole(base);
319319
console.setName("console");
320320
// windows puts an ugly border on this guy
321321
console.setBorder(null);

app/src/processing/app/EditorConsole.java

+38-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
import javax.swing.*;
2727
import javax.swing.text.*;
2828
import java.awt.*;
29+
import java.awt.event.KeyAdapter;
30+
import java.awt.event.KeyEvent;
31+
import java.awt.event.MouseWheelEvent;
2932
import java.io.PrintStream;
3033

3134
import static processing.app.Theme.scale;
@@ -61,7 +64,7 @@ public static void setCurrentEditorConsole(EditorConsole console) {
6164
private SimpleAttributeSet stdOutStyle;
6265
private SimpleAttributeSet stdErrStyle;
6366

64-
public EditorConsole() {
67+
public EditorConsole(final Base base) {
6568
document = new DefaultStyledDocument();
6669

6770
consoleTextPane = new JTextPane(document);
@@ -110,6 +113,40 @@ public EditorConsole() {
110113
setMinimumSize(new Dimension(100, (height * lines)));
111114

112115
EditorConsole.init(stdOutStyle, System.out, stdErrStyle, System.err);
116+
117+
// Add "CTRL scroll" hotkey for font size adjustment.
118+
consoleTextPane.addMouseWheelListener((MouseWheelEvent e) -> {
119+
if (e.isControlDown()) {
120+
if (e.getWheelRotation() < 0) {
121+
base.handleFontSizeChange(1);
122+
} else {
123+
base.handleFontSizeChange(-1);
124+
}
125+
} else {
126+
e.getComponent().getParent().dispatchEvent(e);
127+
}
128+
});
129+
130+
// Add "CTRL (SHIFT) =/+" and "CTRL -" hotkeys for font size adjustment.
131+
consoleTextPane.addKeyListener(new KeyAdapter() {
132+
@Override
133+
public void keyPressed(KeyEvent e) {
134+
if (e.getModifiersEx() == KeyEvent.CTRL_DOWN_MASK
135+
|| e.getModifiersEx() == (KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK)) {
136+
switch (e.getKeyCode()) {
137+
case KeyEvent.VK_PLUS:
138+
case KeyEvent.VK_EQUALS:
139+
base.handleFontSizeChange(1);
140+
break;
141+
case KeyEvent.VK_MINUS:
142+
if (!e.isShiftDown()) {
143+
base.handleFontSizeChange(-1);
144+
}
145+
break;
146+
}
147+
}
148+
}
149+
});
113150
}
114151

115152
public void applyPreferences() {

0 commit comments

Comments
 (0)