MCPcopy
hub / github.com/rrweb-io/rrweb / initSelectionObserver

Function initSelectionObserver

packages/rrweb/src/record/observer.ts:1124–1163  ·  view source on GitHub ↗
(param: observerParam)

Source from the content-addressed store, hash-verified

1122}
1123
1124function 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
1165function initCustomElementObserver({
1166 doc,

Callers 1

initObserversFunction · 0.85

Calls 4

callbackWrapperFunction · 0.90
isBlockedFunction · 0.90
onFunction · 0.90
getIdMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…