MCPcopy Index your code
hub / github.com/ether/etherpad / _correctMarkersInPad

Function _correctMarkersInPad

src/node/handler/PadMessageHandler.ts:1076–1114  ·  view source on GitHub ↗
(atext: AText, apool: AttributePool)

Source from the content-addressed store, hash-verified

1074 * Copied from the Etherpad Source Code. Don't know what this method does excatly...
1075 */
1076const _correctMarkersInPad = (atext: AText, apool: AttributePool) => {
1077 const text = atext.text;
1078
1079 // collect char positions of line markers (e.g. bullets) in new atext
1080 // that aren't at the start of a line
1081 const badMarkers = [];
1082 let offset = 0;
1083 for (const op of deserializeOps(atext.attribs)) {
1084 const attribs = AttributeMap.fromString(op.attribs, apool);
1085 const hasMarker = AttributeManager.lineAttributes.some((a: string) => attribs.has(a));
1086 if (hasMarker) {
1087 for (let i = 0; i < op.chars; i++) {
1088 if (offset > 0 && text.charAt(offset - 1) !== '\n') {
1089 badMarkers.push(offset);
1090 }
1091 offset++;
1092 }
1093 } else {
1094 offset += op.chars;
1095 }
1096 }
1097
1098 if (badMarkers.length === 0) {
1099 return null;
1100 }
1101
1102 // create changeset that removes these bad markers
1103 offset = 0;
1104
1105 const builder = new Builder(text.length);
1106
1107 badMarkers.forEach((pos) => {
1108 builder.keepText(text.substring(offset, pos));
1109 builder.remove(1);
1110 offset = pos + 1;
1111 });
1112
1113 return builder.toString();
1114};
1115
1116/**
1117 * Handles a CLIENT_READY. A CLIENT_READY is the first message from the client

Callers 1

handleUserChangesFunction · 0.85

Calls 4

fromStringMethod · 0.80
pushMethod · 0.80
removeMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected