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
4 changes: 4 additions & 0 deletions debug/org.eclipse.ui.console/plugin.properties
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@ command.copy_without_escapes.name = Copy Text Without ANSI Escapes
command.copy_without_escapes.description = Copy the console content to clipboard, removing the escape sequences
command.enable_disable.name = Enable / Disable ANSI Support
command.enable_disable.description = Enable / disable ANSI Support
command.console.fontZoomIn.name = Zoom In Console Font
command.console.fontZoomIn.description = Increase the console font size
command.console.fontZoomOut.name = Zoom Out Console Font
command.console.fontZoomOut.description = Decrease the console font size
53 changes: 53 additions & 0 deletions debug/org.eclipse.ui.console/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,36 @@ M4 = Platform-specific fourth key
sequence="M1+M2+Insert">
</key>
-->
<key
commandId="org.eclipse.ui.console.command.fontZoomIn"
contextId="org.eclipse.ui.console.ConsoleView"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="M1+=">
</key>
<key
commandId="org.eclipse.ui.console.command.fontZoomIn"
contextId="org.eclipse.ui.console.ConsoleView"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="M1++">
</key>
<key
commandId="org.eclipse.ui.console.command.fontZoomIn"
contextId="org.eclipse.ui.console.ConsoleView"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="M1+NUMPAD_ADD">
</key>
<key
commandId="org.eclipse.ui.console.command.fontZoomOut"
contextId="org.eclipse.ui.console.ConsoleView"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="M1+-">
</key>
<key
commandId="org.eclipse.ui.console.command.fontZoomOut"
contextId="org.eclipse.ui.console.ConsoleView"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="M1+NUMPAD_SUBTRACT">
</key>
</extension>

<extension
Expand Down Expand Up @@ -157,6 +187,29 @@ M4 = Platform-specific fourth key
id="org.eclipse.ui.commands.toggleState">
</state>
</command>
<command
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These commands can be executed via "Ctrl+3", and guess what ... They change editor font, if it is currently active, or "Debug Shell" view font etc.

We need <enabledWhen> on the handler to restrict it to Console view only.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These commands can be executed via "Ctrl+3", and guess what ... They change current editor font, if editor is currently active, or "Debug Shell" view font etc.

We need <enabledWhen> on the handler to restrict it to Console view only.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These commands can be executed via "Ctrl+3", and guess what ... They change current editor font, if editor is currently active, or "Debug Shell" view font etc.

We need <enabledWhen> on the handler to restrict it to Console view only.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These commands can be executed via "Ctrl+3", and guess what ... They change current editor font, if editor is currently active, or "Debug Shell" view font etc.

We need <enabledWhen> on the handler to restrict it to Console view only.

id="org.eclipse.ui.console.command.fontZoomIn"
name="%command.console.fontZoomIn.name"
description="%command.console.fontZoomIn.description"
categoryId="org.eclipse.ui.category.edit">
</command>
<command
id="org.eclipse.ui.console.command.fontZoomOut"
name="%command.console.fontZoomOut.name"
description="%command.console.fontZoomOut.description"
categoryId="org.eclipse.ui.category.edit">
</command>
</extension>

<extension point="org.eclipse.ui.handlers">
<handler
class="org.eclipse.ui.internal.console.ConsoleZoomInHandler"
commandId="org.eclipse.ui.console.command.fontZoomIn">
</handler>
<handler
class="org.eclipse.ui.internal.console.ConsoleZoomOutHandler"
commandId="org.eclipse.ui.console.command.fontZoomOut">
</handler>
</extension>

<extension point="org.eclipse.ui.preferencePages">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*******************************************************************************
* Copyright (c) 2026 Advantest Europe GmbH and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Raghunandana Murthappa
*******************************************************************************/
package org.eclipse.ui.internal.console;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.console.TextConsolePage;

/**
* Command handler to increase the font size of the focused console StyledText.
*
* @since 3.17
*/
public class ConsoleZoomInHandler extends AbstractHandler {
private static final String ZOOM_FONT_KEY = TextConsolePage.class.getName() + ".zoomFont"; //$NON-NLS-1$
private static final String DEBUG_CONSOLE_FONT_REGISTRY_KEY = "org.eclipse.debug.ui.consoleFont"; //$NON-NLS-1$
private static final int MIN_FONT_SIZE = 6;
private static final int MAX_FONT_SIZE = 72;
private static final int STEP = 1;

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
changeFocusedFont(STEP);
return null;
}

private void changeFocusedFont(int delta) {
Comment thread
raghucssit marked this conversation as resolved.
Display display = Display.getCurrent();
if (display == null) {
return;
}
display.syncExec(() -> applyZoom(display, delta));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if Display.getCurrent() != null we are in UI thread already. Why do we need syncExec() then?

}

public static void applyZoom(Display display, int delta) {
// Capture the focused control.
Control focus = display.getFocusControl();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if display.getFocusControl() is not working as expected, but I consistently see various issues with various consoles.

Try to play with 3 diffeent consoles:

  1. Run a simple Java code that outputs some stack trace - this will be the first console.
  2. Copy/paste this trace to "Java stack trace" console - second one.
  3. Open "Host OSGI Console" and type "help" there - third one.

Now open a text editor (Java code or just any plain txt file).

  1. If you "Ctrl +" or "Ctrl+-" in the process output console, it works fine and editor is not affected.
  2. If you "Ctrl +" or "Ctrl+-" in Java Stack Trace console, it automatically increases/decreases editor font size.
  3. If you "Ctrl +" or "Ctrl+-" in "Host OSGI Console", it increases font size in the process output console too, but not otherwise.
  4. And so on, just try with different consoles.
  5. If I open a second Console view, font sizes seem to be properly updated in all consoles, however "Java Stack Trace" page seem to also always change font size in the editor.

My expectations are:

  1. The editor font size should never change if we change font in Console via "Ctrl +" or "Ctrl+-". I guess the problem is that the Java Stack Trace does not properly sets the context and the handler "thinks" it is the editor context. This can7should be fixed in a separated JDT UI fix.
  2. The changes inside different Console pages should ideally work per page only, or (not so nice but acceptable) in all pages, but then at same time, and not via some random logic. So if I change the font size in the Console view, it is always applied consistently to either one or to all opened pages. I guess that switching Console pages doesn't always take the font size change into account if showing the previously hidden page.

StyledText st = focus instanceof StyledText ? (StyledText) focus : null;
if (st == null || st.isDisposed()) {
return;
}
Font current = st.getFont();
if (current == null || current.isDisposed()) {
return;
}
FontData[] fontData = current.getFontData();
if (fontData == null || fontData.length == 0) {
return;
}
int currentHeight = fontData[0].getHeight();
int newHeight = Math.max(MIN_FONT_SIZE, Math.min(MAX_FONT_SIZE, currentHeight + delta));
if (newHeight == currentHeight) {
return;
}
FontData[] newFontData = fontData.clone();
for (FontData fd : newFontData) {
if (fd != null)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please always use blocks for if/for/while statements, independently how many lines are inside.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please always use blocks for if/for/while statements, independently how many lines are inside.

fd.setHeight(newHeight);
}

Font oldZoom = (Font) st.getData(ZOOM_FONT_KEY);
Font newZoom = new Font(st.getDisplay(), newFontData);
st.setFont(newZoom);
st.setData(ZOOM_FONT_KEY, newZoom);
if (oldZoom == null) {
st.addDisposeListener(e -> {
Font z = (Font) st.getData(ZOOM_FONT_KEY);
if (z != null && !z.isDisposed())
z.dispose();
});
}
if (oldZoom != null && !oldZoom.isDisposed()) {
oldZoom.dispose();
}

// Update shared JFace registry so other listeners can observe the change
JFaceResources.getFontRegistry().put(DEBUG_CONSOLE_FONT_REGISTRY_KEY, newFontData);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is responsible for really awkward behavior of different consoles I've observed.

I've tested few consoles and they all behave differently. Looks like consoles from Platform are OK and consistent (process console & ant), but JDT is different (it reads the font set for Console but it also changes the font for the editor) and the Host OSGI Console (PDE) doesn't care at all about default console font, same as SpotBugs (not from eclipse.org).

On one side it makes sense, every contributed console can have their own font defined, on the other side, they could derive their font from the base one.

So ideally we should fix JDT console (which propagates font changes to the editor), and the PDE (which should derive the font from Console preferences). It would make sense to check if CDT build console need some fix and fix that too, but first let fix the platform.

All other 3rd party plugins should fix their code by themselves.

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*******************************************************************************
* Copyright (c) 2026 Advantest Europe GmbH and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Raghunandana Murthappa
*******************************************************************************/
package org.eclipse.ui.internal.console;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.swt.widgets.Display;

/**
* Command handler to decrease the font size of the focused console StyledText.
*
* @since 3.17
*/
public class ConsoleZoomOutHandler extends AbstractHandler {
private static final int STEP = 1;

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of overriding two methods, you can specify protected int getStep() in the super class and only override it here, or do what AbstractTextZoomHandler is doing and have an abstract class that does the job and two strivial handler classes specifying the increment in the constructor.

Also I wonder if the code similar to code in org.eclipse.ui.texteditor.AbstractTextZoomHandler.execute(ExecutionEvent) can be used here (instead of directly modifying StyledText`)?

changeFocusedFont(-STEP);
return null;
}

private void changeFocusedFont(int delta) {
Display display = Display.getCurrent();
if (display == null) {
return;
}
display.syncExec(() -> ConsoleZoomInHandler.applyZoom(display, delta));
}
}
Loading