Skip to content

Conversation

oleksandr-danylchenko
Copy link
Contributor

@oleksandr-danylchenko oleksandr-danylchenko commented Aug 1, 2024

Issue - #127

Changes Made

I made the annotatingEnabled a dynamic property that can receive values from the external sources via the setAnnotatingEnabled (following the "API addition: method to change userSelectAction" example)

(Soomo Staged, 22.09.25)

@oleksandr-danylchenko oleksandr-danylchenko force-pushed the #127-annotating-enabled-reactive branch from dae32c7 to da40d2c Compare August 28, 2024 16:08
Comment on lines 30 to 38
const setAnnotatingEnabled = (enabled: boolean) => {
currentAnnotatingEnabled = enabled;
onSelectionChange.clear();

if (!enabled) {
currentTarget = undefined;
lastPointerDown = undefined;
}
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We must clean the onSelectionChange debounced call to prevent it from running on obsolete values from the closure. Otherwise, the selectionchange event will still get processed in the deferred call, even though the currentAnnotatingEnabled became false.

Copy link
Member

Choose a reason for hiding this comment

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

I wonder how crucial that is though. Would annotatingEnabled get called during a selection in practice? The normal use cases I would see is:

  • Setting it once on page init (because the user is getting a page served in "read-only mode")
  • "Locking a page" interactively, by the user clicking a "Lock" button. (In which case there wouldn't be a selection.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wonder how crucial that is, though.

It shouldn't be extremely crucial. But it's a good tone not to leave hanging callbacks/listeners that might run on obsolete values. I believe it reduces the debugging headache in a long run.

# Conflicts:
#	packages/text-annotator-react/src/TextAnnotator.tsx
#	packages/text-annotator/src/SelectionHandler.ts
# See - sindresorhus/debounce#8. The debounced function has a strict context comparison that breaks when applied in the resize listener
@oleksandr-danylchenko oleksandr-danylchenko marked this pull request as draft August 30, 2024 12:59
@oleksandr-danylchenko oleksandr-danylchenko marked this pull request as ready for review August 30, 2024 14:04
# Conflicts:
#	packages/text-annotator/src/SelectionHandler.ts
# Conflicts:
#	packages/text-annotator/src/TextAnnotator.ts
# Conflicts:
#	packages/text-annotator/src/SelectionHandler.ts
#	packages/text-annotator/src/TextAnnotator.ts
#	packages/text-annotator/src/highlight/baseRenderer.ts
# Conflicts:
#	packages/text-annotator/src/SelectionHandler.ts
#	packages/text-annotator/src/utils/index.ts
# Conflicts:
#	packages/text-annotator/src/SelectionHandler.ts
# Conflicts:
#	packages/text-annotator/src/utils/index.ts
# Conflicts:
#	packages/text-annotator/src/SelectionHandler.ts
# Conflicts:
#	packages/text-annotator/src/SelectionHandler.ts
#	packages/text-annotator/src/TextAnnotator.ts
# Conflicts:
#	packages/text-annotator/src/TextAnnotator.ts
# Conflicts:
#	packages/text-annotator/src/SelectionHandler.ts
# Conflicts:
#	packages/text-annotator/src/SelectionHandler.ts
# Conflicts:
#	packages/text-annotator/src/SelectionHandler.ts
# Conflicts:
#	package-lock.json
#	packages/text-annotator-react/package.json
# Conflicts:
#	package-lock.json
#	packages/text-annotator-react/package.json
#	packages/text-annotator/src/SelectionHandler.ts
#	packages/text-annotator/src/utils/index.ts
const selectionHandler = SelectionHandler(container, state, opts);
const selectionHandler = createSelectionHandler(container, state, opts);
selectionHandler.setUser(currentUser);
selectionHandler.setAnnotatingEnabled(opts.annotatingEnabled);
Copy link
Member

Choose a reason for hiding this comment

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

This line should be redundant, right? Because the initial state would already come in through the opts?

Copy link
Contributor Author

@oleksandr-danylchenko oleksandr-danylchenko Oct 13, 2025

Choose a reason for hiding this comment

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

This line should be redundant, right?

Technically, yes. This explicit call was added before the createSelectionHandler started receiving the opts object.

@rsimon rsimon merged commit 3899a3d into recogito:main Oct 13, 2025
@oleksandr-danylchenko oleksandr-danylchenko deleted the #127-annotating-enabled-reactive branch October 13, 2025 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants