Skip to content

feat: LEAP-1973: Adjustable spans for Text tag #7309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 29 commits into from
Apr 10, 2025

Conversation

hlomzik
Copy link
Collaborator

@hlomzik hlomzik commented Mar 31, 2025

Allow users to resize selected NER regions.

adjust-spans-03.mov

The main idea is to use browser selection with styles of the region so the region expansion will look
smooth and natural. At the beginning the selection will be set to wrap the region. So users will just change
the selection during drag-n-drop, no extra code required for the visual part.

Steps to achieve this:

  1. Detect that user is about to resize the region (mousedown on a handle)
  2. Set selection style to the region's style
  3. Set selection range to the region's range for the initial state
  4. We do nothing on mousemove, and on mouseup we update the region's offsets
  5. Remove selection style

There are some tricky parts here: selection should be created after we started dragging,
if we create it before, then the drag will drag-n-drop the selection instead of continuing it.
Steps and flags on init:

  • mousedown: check if we are on a handle, set draggableRegion and dragBackwards to understand the direction
  • mousemove: if we have draggableRegion but don't have initializedDrag, set it; that means we are dragging
  • mousemove: if we have both, create selection around the region, set currentSelection;
    we are editing the region now
    And we should reset all of them on mouseup.

@github-actions github-actions bot added the feat label Mar 31, 2025
Copy link

netlify bot commented Mar 31, 2025

Deploy Preview for label-studio-storybook ready!

Name Link
🔨 Latest commit 100a7c3
🔍 Latest deploy log https://app.netlify.com/sites/label-studio-storybook/deploys/67f7d2305f6df3000823a35c
😎 Deploy Preview https://deploy-preview-7309--label-studio-storybook.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Mar 31, 2025

Deploy Preview for heartex-docs canceled.

Name Link
🔨 Latest commit 100a7c3
🔍 Latest deploy log https://app.netlify.com/sites/heartex-docs/deploys/67f7d230bb506a00087517b4

Copy link

netlify bot commented Mar 31, 2025

Deploy Preview for label-studio-docs-new-theme canceled.

Name Link
🔨 Latest commit 100a7c3
🔍 Latest deploy log https://app.netlify.com/sites/label-studio-docs-new-theme/deploys/67f7d230c4bf080008d9eabe

@hlomzik hlomzik requested review from Gondragos and Copilot March 31, 2025 14:52
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces drag‑n‑drop editing for text tag regions by adjusting browser selection styles to mimic region styles during resizing.

  • Added new drag‑n‑drop methods for initiating and applying selection styles in RichText view.
  • Integrated resize handle attachment and detachment in the HighlightMixin for better visual cues during region manipulation.
  • Updated imports and helper functions to support global offset calculations.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
web/libs/editor/src/tags/object/RichText/view.jsx Added drag‑n‑drop editing methods and selection style adjustments.
web/libs/editor/src/mixins/HighlightMixin.js Added functions to attach/detach resize handles and updated styles for active regions.
Comments suppressed due to low confidence (1)

web/libs/editor/src/tags/object/RichText/view.jsx:137

  • [nitpick] The function name '_hightlightRegion' appears to contain a typo. Consider renaming it to '_highlightRegion' for improved clarity.
  _hightlightRegion = (_doc, region) => {

hlomzik added 10 commits April 2, 2025 14:16
- no weird selection stays on the screen
- no leftover spans after adjustment in multiline
- correct offsets in all cases
- better naming
- no extra regions created by accident
- remove overflow to show handles in a first row
- adjust line-height to remove the gap between lines
This will improve performance and DX as they will be always in one place.
Internals updated with no problems, so we had to solve two issues with visuals:
- detect changes; for this we store offsets in spans and compare them during visuals update
- update hightlight by recreating spans

`_spans` are added to volatile props to trigger MST views updates.
`force` option was added to `updateHighlightedText()` to update text every time
@hlomzik
Copy link
Collaborator Author

hlomzik commented Apr 7, 2025

/git merge

Workflow run
Successfully merged: create mode 100644 web/libs/ui/src/shadcn.ts

@hlomzik hlomzik requested review from nick-skriabin and bmartel April 8, 2025 09:31
@bmartel
Copy link
Contributor

bmartel commented Apr 8, 2025

Could you add a screenshot of what this looks like?

@hlomzik hlomzik requested a review from nass600 April 8, 2025 15:40
hlomzik added 4 commits April 9, 2025 15:14
Now it's easy to see extended/reduced parts of the region.
The trick is to use lighter color for both region and selection,
and overlapped area will look darker, the same as the original region color.
If it's outside just do nothing to the region, but stop the resizing and reset flags and styles.
To achieve this we have to attach handler to the document and do some tweaks.
Add `canResizeSpans` getter to RichText model and use it
@hlomzik
Copy link
Collaborator Author

hlomzik commented Apr 9, 2025

/git merge

Workflow run
Successfully merged: create mode 100644 web/libs/editor/tests/integration/e2e/control_tags/from-prediction.cy.ts

@MihajloHoma
Copy link
Contributor

MihajloHoma commented Apr 10, 2025

/git merge

Workflow run
Successfully merged: create mode 100644 web/libs/storybook/addons/theme-toggle/theme-toggle.tsx

@MihajloHoma
Copy link
Contributor

MihajloHoma commented Apr 10, 2025

/fm sync

Workflow run

We should not use anything from `apps` in `libs`
@hlomzik
Copy link
Collaborator Author

hlomzik commented Apr 10, 2025

/git merge

Workflow run
Successfully merged: Already up to date.

@hlomzik
Copy link
Collaborator Author

hlomzik commented Apr 10, 2025

@Gondragos thank you, I added link to your comments to follow-up ticket (LEAP-2000)

@hlomzik
Copy link
Collaborator Author

hlomzik commented Apr 10, 2025

/help

Command Description
/frontend [<args> ...] Actions with frontend. Type /frontend help for an additional help.

@hlomzik hlomzik marked this pull request as draft April 10, 2025 13:46
@hlomzik hlomzik marked this pull request as ready for review April 10, 2025 13:47
@hlomzik hlomzik enabled auto-merge (squash) April 10, 2025 14:18
@hlomzik hlomzik merged commit 1ebe781 into develop Apr 10, 2025
40 checks passed
@robot-ci-heartex robot-ci-heartex deleted the fb-leap-1973/adjustable-spans branch April 10, 2025 14:56
@hlomzik
Copy link
Collaborator Author

hlomzik commented Apr 10, 2025

Could you add a screenshot of what this looks like?

Added a video to PR description, thank you for call out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants