eclipse.platform.swt
eclipse.platform.swt copied to clipboard
[Win32] For a Text field with SWT.Verify-listener the Shift+Del shortcut does not work any more
Describe the bug Normally, the legacy shortcut Shift+Del cuts text in a text field on Windows. This works fine by default until you add a SWT.Verify listener to the Text control.
To Reproduce Run this snippet:
import org.eclipse.swt.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
public class TextTest {
public static void main(String[] args) {
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setLayout(new GridLayout(1, false));
final Text text = new Text(shell, SWT.SINGLE | SWT.BORDER);
text.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
text.setText("Hello World");
text.setSelection(6, text.getCharCount());
/*
text.addListener(SWT.Verify, event -> {
System.out.println("verify called");
});
*/
shell.setSize(400, 100);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
}
on Windows and press Shift+Del. "World" will be cut. Now uncomment the SWT.Verify listener and run again. Now Shift+Del does not cut any more.
Expected behavior Shift+Del should work regardless of the SWT.Verify listener.
Environment:
- Select the platform(s) on which the behavior is seen:
-
- [ ] All OS
-
- [x] Windows
-
- [ ] Linux
-
- [ ] macOS
- Additional OS info (e.g. OS version, Linux Desktop, etc) Tried on Windows 11.
~And not just when a verify listener is added to the Text control. It can happen when a Text control is in a wizard or dialog. For example, the Text fields in Eclipse's Preferences pages.~
Edit - I was mistaken. Ignore above.
Does not happen in RCP when there is a custom Command for that key binding (default):
reproducable in Large File Associations preferences:
@jukzi Do these text fields contain an SWT.Verify listener?
yes
(to only allow numeric chars)
Hi, I am able to reproduce the problem only via your snippet. But when tried in below cases, everything works perfectly correct for me.
Case 1:
In the same screen of Large File Associations, when i do => add filter types, for an example if i add *.pdf and select df. Then do a shift+del, even then the text df cuts. The short cut works for me. (Here it is non-numeric field.) Is it not expected to work?
Case 2:
In Web Browser section, when i do an Edit or New, in both the cases where in the Name field, i already have some content and want to edit it. Say select "plo" some content and do a shift+del, it is cutting the selected text. So this is working as expected right. Is it not expected to work?
I tried on the below environment. Eclipse SDK Version: 2025-03 (4.35) Build id: I20241201-1800 OS: Windows 11, v.10.0, x86_64 / win32 Java vendor: Eclipse Adoptium Java runtime version: 23.0.1+11 Java version: 23.0.1
I tried with the SWT binaries from SWT 3.7.1 (from June 2011) and it doesn't work. It seems to have be broken for quite a while now.
@tmssngr are you planning on providing a PR for that?
Since it's been broken for at least 12+ years now, I removed the "regression" label. It's too dated to call it a regression.
@tmssngr are you planning on providing a PR for that?
It makes sense to keep it for the custom-drawn implementation. Could someone please add a label for that?
Well there's the "bug" label already in there. Isn't that enough? Also, keep in mind that if you're talking about the custom-drawn implementation in the initiative 31, it should be some label in the initiative and not here. Or did I misunderstand your comment?
Why not mark issues like this one here with a label "initiative31" (or similar), so it is clear, that it does not need to be resolved right now, but can wait until initiative31 is ready?
I have to admit that I do not understand the relation to Initiative 31. As far as I understand, this is an issue in SWT master (not a regression though). Whether or not someone requires a fix for it is unclear but I do not see why doing the fix should depend on whether a new SWT implementation is available or not.
@tmssngr We have the same problem with Shift+Del in our RCP app using a SWT.Verify listener on Text controls. Did you figure out a workaround?
@Phillipus No, not yet.
These lines block the Shift+Del combination in the Text control:
https://github.com/eclipse-platform/eclipse.platform.swt/blob/925a294b8028e9d26593c6105efce56f95dc9b56/bundles/org.eclipse.swt/Eclipse%20SWT/win32/org/eclipse/swt/widgets/Text.java#L1802-L1814
I don't know what the workaround would be, maybe check for Shift+Del?
if ((stateMask & (SWT.ALT | SWT.SHIFT | SWT.CONTROL)) != 0 && key != 0x7f) return false;