eclipse.platform.swt icon indicating copy to clipboard operation
eclipse.platform.swt copied to clipboard

[Win32] For a Text field with SWT.Verify-listener the Shift+Del shortcut does not work any more

Open tmssngr opened this issue 1 year ago • 8 comments
trafficstars

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:

  1. Select the platform(s) on which the behavior is seen:
    • [ ] All OS
    • [x] Windows
    • [ ] Linux
    • [ ] macOS
  1. Additional OS info (e.g. OS version, Linux Desktop, etc) Tried on Windows 11.

tmssngr avatar Sep 13 '24 13:09 tmssngr

~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.

Phillipus avatar Sep 13 '24 16:09 Phillipus

Does not happen in RCP when there is a custom Command for that key binding (default): image reproducable in Large File Associations preferences: image

jukzi avatar Sep 13 '24 22:09 jukzi

@jukzi Do these text fields contain an SWT.Verify listener?

tmssngr avatar Sep 14 '24 11:09 tmssngr

yes

jukzi avatar Sep 14 '24 11:09 jukzi

(to only allow numeric chars)

jukzi avatar Sep 14 '24 11:09 jukzi

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: image

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: image

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

deepika-u avatar Dec 03 '24 10:12 deepika-u

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?

fedejeanne avatar May 09 '25 10:05 fedejeanne

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.

fedejeanne avatar May 09 '25 10:05 fedejeanne

@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?

tmssngr avatar May 13 '25 10:05 tmssngr

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?

fedejeanne avatar May 13 '25 10:05 fedejeanne

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?

tmssngr avatar May 13 '25 12:05 tmssngr

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.

HeikoKlare avatar May 13 '25 13:05 HeikoKlare

@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 avatar May 28 '25 10:05 Phillipus

@Phillipus No, not yet.

tmssngr avatar May 28 '25 13:05 tmssngr

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;

Phillipus avatar May 28 '25 15:05 Phillipus