(transaction: Transaction)
| 110 | } |
| 111 | |
| 112 | function createPairedRename(transaction: Transaction): ChangeSpec | null { |
| 113 | if ( |
| 114 | !transaction.docChanged || |
| 115 | transaction.annotation(skipTagAutoRename) || |
| 116 | transaction.annotation(Transaction.remote) |
| 117 | ) { |
| 118 | return null; |
| 119 | } |
| 120 | |
| 121 | const ranges = getChangedRanges(transaction); |
| 122 | if (ranges.length !== 1) return null; |
| 123 | |
| 124 | const [change] = ranges; |
| 125 | const target = getRenameTarget( |
| 126 | transaction.startState, |
| 127 | change.fromA, |
| 128 | change.toA, |
| 129 | ); |
| 130 | if (!target || !touchesRange(change, target.tagName.from, target.tagName.to)) { |
| 131 | return null; |
| 132 | } |
| 133 | if ( |
| 134 | touchesRange( |
| 135 | change, |
| 136 | target.pairedTagName.from, |
| 137 | target.pairedTagName.to, |
| 138 | ) |
| 139 | ) { |
| 140 | return null; |
| 141 | } |
| 142 | |
| 143 | const editedRange = mapEditedRange( |
| 144 | transaction, |
| 145 | target.tagName.from, |
| 146 | target.tagName.to, |
| 147 | ); |
| 148 | const newName = transaction.newDoc.sliceString( |
| 149 | editedRange.from, |
| 150 | editedRange.to, |
| 151 | ); |
| 152 | if (newName && !tagNamePattern.test(newName)) return null; |
| 153 | |
| 154 | return { |
| 155 | from: target.pairedTagName.from, |
| 156 | to: target.pairedTagName.to, |
| 157 | insert: newName, |
| 158 | }; |
| 159 | } |
| 160 | |
| 161 | export default function tagAutoRename(): Extension { |
| 162 | return EditorState.transactionFilter.of((transaction) => { |
no test coverage detected