(param: observerParam)
| 1122 | } |
| 1123 | |
| 1124 | function initSelectionObserver(param: observerParam): listenerHandler { |
| 1125 | const { doc, mirror, blockClass, blockSelector, selectionCb } = param; |
| 1126 | let collapsed = true; |
| 1127 | |
| 1128 | const updateSelection = callbackWrapper(() => { |
| 1129 | const selection = doc.getSelection(); |
| 1130 | |
| 1131 | if (!selection || (collapsed && selection?.isCollapsed)) return; |
| 1132 | |
| 1133 | collapsed = selection.isCollapsed || false; |
| 1134 | |
| 1135 | const ranges: SelectionRange[] = []; |
| 1136 | const count = selection.rangeCount || 0; |
| 1137 | |
| 1138 | for (let i = 0; i < count; i++) { |
| 1139 | const range = selection.getRangeAt(i); |
| 1140 | |
| 1141 | const { startContainer, startOffset, endContainer, endOffset } = range; |
| 1142 | |
| 1143 | const blocked = |
| 1144 | isBlocked(startContainer, blockClass, blockSelector, true) || |
| 1145 | isBlocked(endContainer, blockClass, blockSelector, true); |
| 1146 | |
| 1147 | if (blocked) continue; |
| 1148 | |
| 1149 | ranges.push({ |
| 1150 | start: mirror.getId(startContainer), |
| 1151 | startOffset, |
| 1152 | end: mirror.getId(endContainer), |
| 1153 | endOffset, |
| 1154 | }); |
| 1155 | } |
| 1156 | |
| 1157 | selectionCb({ ranges }); |
| 1158 | }); |
| 1159 | |
| 1160 | updateSelection(); |
| 1161 | |
| 1162 | return on('selectionchange', updateSelection); |
| 1163 | } |
| 1164 | |
| 1165 | function initCustomElementObserver({ |
| 1166 | doc, |
no test coverage detected
searching dependent graphs…