Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
model.change(writer => {
if (toggleMode && !value) {
const rangesToUnset = selection.isCollapsed ?
[findLinkRange(selection.getFirstPosition(), selection.getAttribute('linkHref'), model)] : selection.getRanges();
for (const range of rangesToUnset) {
writer.removeAttribute(this.attributeKey, range);
}
} else if (selection.isCollapsed) {
const position = selection.getFirstPosition();
if (selection.hasAttribute('linkHref')) {
const linkRange = findLinkRange(selection.getFirstPosition(), selection.getAttribute('linkHref'), model);
if (value === false) {
writer.removeAttribute(this.attributeKey, linkRange);
} else {
writer.setAttribute(this.attributeKey, value, linkRange);
writer.setSelection(linkRange);
}
} else if (value !== '') {
const attributes = toMap(selection.getAttributes());
model.change(writer => {
if (toggleMode && !value) {
const rangesToUnset = selection.isCollapsed ?
[findLinkRange(selection.getFirstPosition(), selection.getAttribute('linkHref'), model)] : selection.getRanges();
for (const range of rangesToUnset) {
writer.removeAttribute(this.attributeKey, range);
}
} else if (selection.isCollapsed) {
const position = selection.getFirstPosition();
if (selection.hasAttribute('linkHref')) {
const linkRange = findLinkRange(selection.getFirstPosition(), selection.getAttribute('linkHref'), model);
if (value === false) {
writer.removeAttribute(this.attributeKey, linkRange);
} else {
writer.setAttribute(this.attributeKey, value, linkRange);
writer.setSelection(linkRange);
}
} else if (value !== '') {
const attributes = toMap(selection.getAttributes());
attributes.set(this.attributeKey, value);
const node = writer.createText(value, attributes);
writer.insert(node, position);
writer.setSelection(Range.createOn(node));
}
} else {
const ranges = model.schema.getValidRanges(selection.getRanges(), this.attributeKey);