Commit ec7b8b0
Fix commands being executed twice due to stale isEnabled() check #4080
In commit 35f5f09, the commandHandled evaluation in
KeyBindingDispatcher.executeCommand() was changed to include
command.isEnabled() in addition to handler.isHandled(). This causes
commands to be executed twice (e.g. Paste on a Combo widget):
- command.isEnabled() reads the handler's enabled state without first
calling setEnabled(evaluationContext), so it returns stale state that
does not reflect the currently focused widget context.
- Inside Command.executeWithChecks(), the framework calls
setEnabled(event.getApplicationContext()) immediately before the same
isEnabled() check, giving a fresh result. The two checks are not
equivalent and can disagree for IHandler2 implementations.
- When command.isEnabled() incorrectly returns false, commandHandled is
false, executeCommand() returns false, and the key event is not
consumed (event.doit remains true) even though the command is actually
executed. The OS then processes the keystroke natively, causing a
second execution of the same action.
Fix 1: Revert determination of successful command handling to use only
handler.isHandled(), as it was before commit 35f5f09.
Fix 2: Change handleCommandExecution() to return a boolean (false if a
CommandException was recorded after execution) and use that return value
to update commandHandled in the synchronous non-Browser path. This
restores the original behaviour where a handler that claims isHandled()
but fails during execution (e.g. NotEnabledException after a fresh
setEnabled() evaluation) does not eat the key event. The async Browser
path is unchanged by design.
Fixes #40801 parent 130a4ef commit ec7b8b0
2 files changed
Lines changed: 62 additions & 3 deletions
File tree
- bundles/org.eclipse.e4.ui.bindings/src/org/eclipse/e4/ui/bindings/keys
- tests/org.eclipse.e4.ui.bindings.tests/src/org/eclipse/e4/ui/bindings/tests
Lines changed: 5 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
304 | 304 | | |
305 | 305 | | |
306 | 306 | | |
307 | | - | |
| 307 | + | |
308 | 308 | | |
309 | 309 | | |
310 | 310 | | |
| |||
319 | 319 | | |
320 | 320 | | |
321 | 321 | | |
322 | | - | |
| 322 | + | |
323 | 323 | | |
324 | 324 | | |
325 | 325 | | |
326 | 326 | | |
327 | | - | |
| 327 | + | |
328 | 328 | | |
329 | 329 | | |
330 | 330 | | |
| |||
360 | 360 | | |
361 | 361 | | |
362 | 362 | | |
| 363 | + | |
363 | 364 | | |
364 | 365 | | |
365 | 366 | | |
| |||
371 | 372 | | |
372 | 373 | | |
373 | 374 | | |
| 375 | + | |
374 | 376 | | |
375 | 377 | | |
376 | 378 | | |
| |||
tests/org.eclipse.e4.ui.bindings.tests/src/org/eclipse/e4/ui/bindings/tests/KeyDispatcherTest.java
Lines changed: 57 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
| 20 | + | |
19 | 21 | | |
20 | 22 | | |
21 | 23 | | |
| |||
24 | 26 | | |
25 | 27 | | |
26 | 28 | | |
| 29 | + | |
27 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
28 | 34 | | |
29 | 35 | | |
30 | 36 | | |
| |||
197 | 203 | | |
198 | 204 | | |
199 | 205 | | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
200 | 257 | | |
201 | 258 | | |
202 | 259 | | |
| |||
0 commit comments