(attributeName)
| 1639 | editorInfo.ace_getAttributeOnSelection = getAttributeOnSelection; |
| 1640 | |
| 1641 | const toggleAttributeOnSelection = (attributeName) => { |
| 1642 | if (!(rep.selStart && rep.selEnd)) return; |
| 1643 | |
| 1644 | let selectionAllHasIt = true; |
| 1645 | const withIt = new AttributeMap(rep.apool).set(attributeName, 'true').toString(); |
| 1646 | const withItRegex = new RegExp(`${withIt.replace(/\*/g, '\\*')}(\\*|$)`); |
| 1647 | |
| 1648 | const hasIt = (attribs) => withItRegex.test(attribs); |
| 1649 | |
| 1650 | const selStartLine = rep.selStart[0]; |
| 1651 | const selEndLine = rep.selEnd[0]; |
| 1652 | for (let n = selStartLine; n <= selEndLine; n++) { |
| 1653 | let indexIntoLine = 0; |
| 1654 | let selectionStartInLine = 0; |
| 1655 | if (documentAttributeManager.lineHasMarker(n)) { |
| 1656 | selectionStartInLine = 1; // ignore "*" used as line marker |
| 1657 | } |
| 1658 | let selectionEndInLine = rep.lines.atIndex(n).text.length; // exclude newline |
| 1659 | if (n === selStartLine) { |
| 1660 | selectionStartInLine = rep.selStart[1]; |
| 1661 | } |
| 1662 | if (n === selEndLine) { |
| 1663 | selectionEndInLine = rep.selEnd[1]; |
| 1664 | } |
| 1665 | for (const op of deserializeOps(rep.alines[n])) { |
| 1666 | const opStartInLine = indexIntoLine; |
| 1667 | const opEndInLine = opStartInLine + op.chars; |
| 1668 | if (!hasIt(op.attribs)) { |
| 1669 | // does op overlap selection? |
| 1670 | if (!(opEndInLine <= selectionStartInLine || opStartInLine >= selectionEndInLine)) { |
| 1671 | selectionAllHasIt = false; |
| 1672 | break; |
| 1673 | } |
| 1674 | } |
| 1675 | indexIntoLine = opEndInLine; |
| 1676 | } |
| 1677 | if (!selectionAllHasIt) { |
| 1678 | break; |
| 1679 | } |
| 1680 | } |
| 1681 | |
| 1682 | |
| 1683 | const attributeValue = selectionAllHasIt ? '' : 'true'; |
| 1684 | documentAttributeManager.setAttributesOnRange( |
| 1685 | rep.selStart, rep.selEnd, [[attributeName, attributeValue]]); |
| 1686 | if (attribIsFormattingStyle(attributeName)) { |
| 1687 | updateStyleButtonState(attributeName, !selectionAllHasIt); // italic, bold, ... |
| 1688 | } |
| 1689 | }; |
| 1690 | editorInfo.ace_toggleAttributeOnSelection = toggleAttributeOnSelection; |
| 1691 | |
| 1692 | const performDocumentReplaceSelection = (newText) => { |
no test coverage detected