Commit Graph

35 Commits

Author SHA1 Message Date
Ben Henning
bbd97eab67 fix: Synchronize gestures and focus (#8981)
## The basics

- [x] I [validated my changes](https://developers.google.com/blockly/guides/contribute/core#making_and_verifying_a_change)

## The details
### Resolves

Fixes #8952
Fixes #8950
Fixes #8971

Fixes a bunch of other keyboard + mouse synchronization issues found during the testing discussed in https://github.com/google/blockly-keyboard-experimentation/pull/482#issuecomment-2846341307.

### Proposed Changes

This introduces a number of changes to:
- Ensure that gestures which change selection state also change focus.
- Ensure that ephemeral focus is more robust against certain classes of failures.

### Reason for Changes

There are some ephemeral focus issues that can come up with certain actions (like clicking or dragging) don't properly change focus. Beyond that, some users will likely mix clicking and keyboard navigation, so it's essential that focus and selection state stay in sync when switching between these two types of navigation modalities.

Other changes:
- Drop-down div was actually incorrectly releasing ephemeral focus before animated closes finish which could reset focus afterwards, breaking focus state.
- Both drop-down and widget divs have been updated to only return focus _after_ marking the workspace as focused since the last focused node should always be the thing returned.
- In a number of gesture cases selection has been removed. This is due to `BlockSvg` self-managing its selection state based on focus, so focusing is sufficient. I've also centralized some of the focusing calls (such as putting one in `bringBlockToFront` to ensure focusing happens after potential DOM changes).
- Similarly, `BlockSvg`'s own `bringToFront` has been updated to automatically restore focus after the operation completes. Since `bringToFront` can always result in focus loss, this provides robustness to ensure focus is restored.
- Block pasting now ensures that focus is properly set, however a delay is needed due to additional rendering changes that need to complete (I didn't dig deeply into the _why_ of this).
- Dragging has been updated to always focus the moved block if it's not in the process of being deleted.
- There was some selection resetting logic removed from gesture's `doWorkspaceClick` function. As far as I can tell, this won't be needed anymore since blocks self-regulate their selection state now.
- `FocusManager` has a new extra check for ephemeral focus to catch a specific class of failure where the browser takes away focus immediately after it's returned. This can happen if there are delay timing situations (like animations) which result in a focused node being deleted (which then results in the document body receiving focus). The robustness check is possibly not needed, but it help discover the animation issue with drop-down div and shows some promise for helping to fix the variables-closing-flyout problem.

Some caveats:
- Some undo/redo steps can still result in focus being lost. This may introduce some regressions for selection state, and definitely introduces some annoyances with keyboard navigation. More work will be needed to understand how to better redirect focus (and to what) in cases when blocks disappear.
- There are many other places where focus is being forced or selection state being overwritten that could, in theory, cause issues with focus state. These may need to be fixed in the future.
- There's a lot of redundancy with `focusNode` being called more than it needs to be. `FocusManager` does avoid calling `focus()` more than once for the same node, but it's possible for focus state to switch between multiple nodes or elements even for a single gesture (for example, due to bringing the block to the front causing a DOM refresh). While the eventual consistency nature of the manager means this isn't a real problem, it may cause problems with screen reader output in the future and warrant another pass at reducing `focusNode` calls (particularly for gestures and the click event pipeline).

### Test Coverage

This PR is largely relying on existing tests for regression verification, though no new tests have been added for the specific regression cases.

#8910 is tracking improving `FocusManager` tests which could include some cases for the new ephemeral focus improvements.

#8915 is tracking general accessibility testing which could include adding tests for these specific regression cases.

### Documentation

No new documentation is expected to be needed here.

### Additional Information

These changes originate from both #8875 and from a branch @rachel-fenichel created to investigate some of the failures this PR addresses. These changes have also been verified against both Core's playground and the keyboard navigation plugin's test environment.
2025-05-05 10:29:20 -07:00
Christopher Allen
b9b40f48ab fix: Fix bug in BlockSvg.prototype.setParent (#8934)
* test(BlockSvg): Add tests for setParent(null) when dragging

  Add tests for scenarios where block(s) unrelated to the block
  being disconnected has/have been marked as as being dragged.
  Due to a bug in BlockSvg.prototype.setParent, one of these
  fails in the case that the dragging block is not a top
  block.

  Also add a check to assertNonParentAndOrphan to check that the
  orphan block's SVG root's parent is the workspace's canvass
  (i.e., that orphan is a top-level block in the DOM too).

* fix(BlockSvg): Fix bug in setParent re: dragging block

  Fix an incorrect assumption in setParent: the topmost block
  whose root SVG element has the blocklyDragging class may not
  actually be a top-level block.

* refactor(BlockDragStrategy): Hide connection preview earlier

* chore(BlockDragStrategy): prefer ?. to !.

  Per nit on PR #8934.

* fix(BlockSvg): Spelling: "canvass" -> "canvas"
2025-04-29 15:15:42 +00:00
Rachel Fenichel
76b02de654 feat: add getSearchRadius to BlockDragStrategy (#8871) 2025-04-07 13:52:15 -07:00
Rachel Fenichel
49387ec788 feat: add shouldHealStack method (#8872)
* feat: add shouldHealStack method

* chore: format
2025-04-07 12:44:40 -07:00
RoboErikG
b343a13bbe fix: Fixes #8764 by moving the event grouping calls up to dragger.ts (#8781) 2025-02-20 08:56:57 -08:00
Aaron Dodson
343c2f51f3 feat: Add support for toggling readonly mode. (#8750)
* feat: Add methods for toggling and inspecting the readonly state of a workspace.

* refactor: Use the new readonly setters/getters in place of checking the injection options.

* fix: Fix bug that allowed dragging blocks from a flyout onto a readonly workspace.

* feat: Toggle a `blocklyReadOnly` class when readonly status is changed.

* chore: Placate the linter.

* chore: Placate the compiler.
2025-01-30 13:47:36 -08:00
Mateus S. Pereira
7219800183 fix: workspace shifts when deleting a block (#8666)
* fix: workspace shifts when deleting a block

* fix: awaiting for block rerender

* fix: create reusable method to prevent marking method as async
2024-12-04 09:25:01 -08:00
Chang Min Bark
4d0fd5db79 fix(comments): added workspace comments and comment drag strategy isDeadOrDying() checks (#8532)
* fix: added id to rendered ws comments; made getCommentById public; added blocklyDraggable class to ws comments

* fix: added workspace comments and comment drag strategy isDeadOrDying checks

* chore: removed .idea files

* chore: formatted with prettier
2024-09-03 17:12:40 +01:00
Christopher Allen
7ccdcc5cef refactor(events): introduce EventType enum in separate module (#8530)
* refactor(events): Use "export ... from" where applicable

* refactor(events): Introduce EventType enum

  Introduce an enum for the event .type values.  We can't actually
  use it as the type of the .type property on Abstract events,
  because we want to allow developers to add their own custom
  event types inheriting from this type, but at least this way we
  can be reasonably sure that all of our own event subclasses have
  distinct .type values—plus consistent use of enum syntax
  (EventType.TYPE_NAME) is probably good for readability overall.

  Put it in a separate module from the rest of events/utils.ts
  because it would be helpful if event utils could use

      event instanceof SomeEventType

  for type narrowing but but at the moment most events are in
  modules that depend on events/utils.ts for their .type
  constant, and although circular ESM dependencies should work
  in principle there are various restrictions and this
  particular circularity causes issues at the moment.

  A few of the event classes also depend on utils.ts for fire()
  or other functions, which will be harder to deal with, but at
  least this commit is win in terms of reducing the complexity
  of our dependencies, making most of the Abstract event subclass
  module dependent on type.ts, which has no imports, rather than
  on utils.ts which has multiple imports.
2024-08-20 08:36:33 +01:00
Christopher Allen
ce22f42868 chore: Organise imports (#8527)
* chore(deps): Add pretter-plugin-organize-imports

* chore: Remove insignificant blank lines in import sections

  Since prettier-plugin-organize-imports sorts imports within
  sections separated by blank lines, but preserves the section
  divisions, remove any blank lines that are not dividing imports
  into meaningful sections.

  Do not remove blank lines separating side-effect-only imports
  from main imports.

* chore: Remove unneded eslint-disable directives

* chore: Organise imports
2024-08-15 03:16:14 +01:00
dependabot[bot]
f57ef73aaf chore(deps): bump @typescript-eslint/eslint-plugin from 7.17.0 to 8.0.1 (#8479)
* chore(deps): bump @typescript-eslint/eslint-plugin from 7.17.0 to 8.0.1

Bumps [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/eslint-plugin) from 7.17.0 to 8.0.1.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v8.0.1/packages/eslint-plugin)

---
updated-dependencies:
- dependency-name: "@typescript-eslint/eslint-plugin"
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* fix: lint plugin versions

* chore: fix linting

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Beka Westberg <bwestberg@google.com>
2024-08-14 09:10:34 -07:00
ℍ𝕠𝕝𝕝𝕠𝕨 𝕄𝕒𝕟
504de6a98c fix: drag strategy only clear group id set by us (#8355)
Add a condition check so that we don't unset
the group ID that is not set by us. Otherwise the
multi-select plugin undo/redo will be broken (apply
individually instead of all together)

Signed-off-by: Hollow Man <hollowman@opensuse.org>
2024-07-25 22:09:10 +01:00
John Nesky
9a0619aa2a fix: Drag and Resize events for workspace comments (#8217)
* feat: Added a comment_drag event.

* Add workspace comment resize events.

* Addressing PR feedback.

* Fixed chai imports in new test files.

* Addressing more PR feedback.
2024-06-26 12:16:56 -07:00
Beka Westberg
dc91c3ab54 fix: c-blocks disappearing (#8203) 2024-06-11 11:21:48 -07:00
Beka Westberg
6e4ba00be5 fix: dragging and disposing of shadows (#8172)
* Revert "fix: dragging blocks by shadows to delete (#8138)"

This reverts commit 3fd749205f.

* fix: dragging shadows
2024-05-28 10:28:16 -07:00
Beka Westberg
7c4b0bd703 fix: delete area animation (#8149)
* fix: delete area animation

* chore: format

* Update core/dragging/dragger.ts

Co-authored-by: Christopher Allen <cpcallen+github@gmail.com>

---------

Co-authored-by: Christopher Allen <cpcallen+github@gmail.com>
2024-05-20 09:58:48 -07:00
Beka Westberg
3fd749205f fix: dragging blocks by shadows to delete (#8138)
* Revert "fix: dragging shadow blocks (#7992)"

This reverts commit c0e6e6745f.

* fix: dragging by shadow not being deletable

* fix: unselecting shadows

* fix: revert changes to select and unselect
2024-05-17 13:22:53 -07:00
Beka Westberg
75d81620ab fix: undoing block delete over trashcan creates block in wrong place (#8126) 2024-05-17 12:26:10 -07:00
Beka Westberg
44db3edce3 fix: comment move events and snapping (#8127) 2024-05-17 08:26:23 -07:00
Beka Westberg
a865744b7e fix: bumping comments into bounds (#8037) 2024-04-17 14:02:46 -07:00
Beka Westberg
a0f821a239 fix: revert dragger name (#8020) 2024-04-11 13:22:17 -07:00
Beka Westberg
7491a50239 fix: compatibility with scroll plugin (#8016) 2024-04-08 13:17:03 -07:00
Beka Westberg
3e1e9b5ddc fix: blocks not being returned to the correct layer if their drag is reverted with no parent (#7998)
* fix: blocks not being returned to the correct drag layer if their drag is reverted with no parent

* fix: delete test code
2024-04-08 09:44:31 -07:00
Beka Westberg
6f7e04d8eb fix: bubbles not being returned to the correct drag layer (#7997) 2024-04-05 13:46:28 -07:00
Beka Westberg
c0e6e6745f fix: dragging shadow blocks (#7992)
* fix: dragging shadow blocks

* fix: dragging shadows not reverting them to their original position

* fix: shadow parents not being deselected
2024-04-04 18:30:41 +00:00
Beka Westberg
ed403d0b77 feat!: change gestures to look at selected when dragging (#7991)
* feat: change gestures to look at selected when dragging

* chore: fix tests

* chore: format

* chore: PR comments
2024-04-04 08:52:43 -07:00
Beka Westberg
9effba5ee1 feat: make comment a draggable (#7976)
* feat: add drag strategy

* chore: use draggable
2024-04-01 10:25:43 -07:00
Beka Westberg
abfbbbc299 fix!: various drag-adjacent interfaces (#7975)
* fix: ISelectable and IDeletable interfaces

* fix: switch everything over to use new draggable interface

* fix: exports
2024-03-29 21:00:56 +00:00
Beka Westberg
59f589c32a feat!: migrate bubble dragging to use new API (#7974) 2024-03-29 11:02:47 -07:00
Beka Westberg
da8a83b925 feat: have the gesture use a dragger for blocks (#7972)
* feat: have block use drag strategy

* fix: gesture to use dragger for blocks

* chore: register dragger

* chore: remove getInsertionMarkers and pull logic into workspace
2024-03-28 17:38:58 -07:00
Beka Westberg
75fc4704da feat: have block use drag strategy (#7971) 2024-03-28 17:15:36 -07:00
Beka Westberg
8b6e9d8cad feat: add block drag strategy (#7970)
* feat: add the block drag strategy

* chore: remove underscores

* chore: make crazy condition clearer?

* chore: rename var
2024-03-28 16:05:04 -07:00
Beka Westberg
da79a120f2 fix: remove parameter from wouldDelete (#7968) 2024-03-28 15:39:48 -07:00
Beka Westberg
6fe080bc6e fix: draggable interface and concrete dragger (#7967)
* fix: interface to match design

* fix: dragger implementation

* fix: rename moveToStart to revertDrag

* fixup
2024-03-28 15:11:30 -07:00
Christopher Allen
0588dfade8 feat(dragging): Introduce Dragger, implementing IDragger (#7956)
* feat(dragging): Introduce Dragger, implementing iDragger

* docs(dragging): JSDoc for Dragger's .startLoc
2024-03-22 19:03:57 +00:00