Skip to content

Commit

Permalink
Merge pull request #528 from performant-software/bugfix/prevent-highl…
Browse files Browse the repository at this point in the history
…ight-dupe

Prevent duplicate highlights from being created on multiline selections
  • Loading branch information
blms authored Oct 14, 2024
2 parents 8c624ea + 3948c63 commit 56c4acd
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions client/src/TextResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -1285,13 +1285,14 @@ class TextResource extends Component {
let alteredHighlights = [];
let effectedMarks = [];
const editorState = this.getEditorState();
if (steps.length > 0 && steps.every((step) => step instanceof AddMarkStep && step.mark.type.name === this.state.documentSchema.marks.highlight.name)) {
// on highlight, will create 1 AddMarkStep per line break / element crossing
// save one new highlight for the entire range
this.createHighlight(steps[0].mark, tx.curSelection.content(), serializer);
}
steps.forEach(step => {
// save new highlight
if (step instanceof AddMarkStep && step.mark.type.name === this.state.documentSchema.marks.highlight.name) {
this.createHighlight(step.mark, tx.curSelection.content(), serializer);
}
// process highlights that have been removed or altered by a text content change or a mark toggle
else if (step instanceof ReplaceStep || (step instanceof RemoveMarkStep && step.mark.type.name === this.state.documentSchema.marks.highlight.name)) {
if (step instanceof ReplaceStep || (step instanceof RemoveMarkStep && step.mark.type.name === this.state.documentSchema.marks.highlight.name)) {
// TODO: handle case where the space between two highlights is eliminated
// pad the range where we look for effected highlights in order to accommodate edge cases with cursor at beginning or end of highlight
let from = Math.max(step.from - 1, 0), to = step.to;
Expand Down

0 comments on commit 56c4acd

Please sign in to comment.