Autoremove the previous unsaved annotation when a new piece of text is selected #519
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
@JeltevanBoheemen I'm asking
@tijmenbaarda@oktaal to review the code, but the content of this post is also for your information.I kind of repurposed #311, which can no longer be reproduced, to represent a similar issue I described in #311 (comment). This branch addresses the latter issue. I thought I fixed that bug on the 0.14.0 release branch (#518), but I apparently didn't, probably because I glanced over the issue title in the project board and mistook it for a different issue that I did solve. The bugfix is not terribly urgent, so it can wait until the next release.
In the READ-IT interface, users can create annotations by selecting a piece of text. We implement this by creating a temporary annotation object, adding it to the collection of (otherwise "real") annotations and then opening an editing panel so that the user can tag and optionally identify the selection. If the user saves the changes, the annotation is persisted to the backend. It stays in the collection of annotations in this case. The user can also cancel the annotation, in which case the temporary object is removed from the collection again.
Before the current fix, the temporary object would also stay in the collection if the user selected another piece of text without explicitly saving or canceling the previous selection first. In this way, it was possible to accumulate "ghost annotations". The ghosts would stay visible until the source was reloaded.
The fix employs a feature of the collection which enables it to keep track of which annotation is currently supposed to be in the center of attention. A
focus
event is fired on the annotation that must be emphasized. This will automatically triggerblur
on the annotation that was previously emphasized, if any. If the temporary object blurs without having been saved (isBlank
), we know that it must be removed.@tijmenbaarda The code change is actually very small, because the
focus
/blur
infrastructure that I described above was already in place. I just needed to tap into it in this particular situation. Our frontend code in EDPOP will look somewhat similar, with events loosely connecting different parts of the code (though without TypeScript), so this seemed like a gentle first introduction. It is OK if you cannot follow the bigger picture yet, reviewing just code details line-by-line is enough.