Skip to content

Commit

Permalink
🐛 Fix pre selection (#4872)
Browse files Browse the repository at this point in the history
  • Loading branch information
damianpumar authored May 24, 2024
1 parent b228f43 commit c701642
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ export class SpanSelection {

const newSelection = { ...selection };

const filteredSelections = this.selections.filter(
(s) => s.node.id === newSelection.node.id
);

if (!config?.allowCharacter) {
if (this.isEmpty(newSelection.text)) return;

Expand All @@ -78,22 +74,6 @@ export class SpanSelection {
this.completeRightSide(newSelection);
}

const overlaps = this.selections.filter((s) => {
return (
(newSelection.from <= s.from && newSelection.to >= s.to) ||
(newSelection.from >= s.from && newSelection.to <= s.to) ||
(newSelection.from < s.from && newSelection.to > s.from) ||
(newSelection.from < s.to && newSelection.to > s.to)
);
});

if (!config?.allowOverlap) {
this.selections = [
...this.selections.filter((s) => s.node.id !== newSelection.node.id),
...filteredSelections.filter((s) => !overlaps.includes(s)),
];
}

const { from, to, entity, text, node } = newSelection;

const span = {
Expand All @@ -115,6 +95,26 @@ export class SpanSelection {

if (!span) return;

const filteredSelections = this.selections.filter(
(s) => s.node.id === span.node.id
);

const overlaps = this.selections.filter((s) => {
return (
(span.from <= s.from && span.to >= s.to) ||
(span.from >= s.from && span.to <= s.to) ||
(span.from < s.from && span.to > s.from) ||
(span.from < s.to && span.to > s.to)
);
});

if (!config?.allowOverlap) {
this.selections = [
...this.selections.filter((s) => s.node.id !== span.node.id),
...filteredSelections.filter((s) => !overlaps.includes(s)),
];
}

this.select(span);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { settingsFake, settingsFakeWith12Elements } from "../ranking-fakes";

let wrapper = null;
const options = {
stubs: ["draggable"],
stubs: ["draggable", "BaseTooltip"],
propsData: { ranking: {} },
};

Expand Down

0 comments on commit c701642

Please sign in to comment.