| 204 | // Used both to provide a JSON-safe object in .getHistory, and, when |
| 205 | // detaching a document, to split the history in two |
| 206 | export function copyHistoryArray(events, newGroup, instantiateSel) { |
| 207 | let copy = [] |
| 208 | for (let i = 0; i < events.length; ++i) { |
| 209 | let event = events[i] |
| 210 | if (event.ranges) { |
| 211 | copy.push(instantiateSel ? Selection.prototype.deepCopy.call(event) : event) |
| 212 | continue |
| 213 | } |
| 214 | let changes = event.changes, newChanges = [] |
| 215 | copy.push({changes: newChanges}) |
| 216 | for (let j = 0; j < changes.length; ++j) { |
| 217 | let change = changes[j], m |
| 218 | newChanges.push({from: change.from, to: change.to, text: change.text}) |
| 219 | if (newGroup) for (var prop in change) if (m = prop.match(/^spans_(\d+)$/)) { |
| 220 | if (indexOf(newGroup, Number(m[1])) > -1) { |
| 221 | lst(newChanges)[prop] = change[prop] |
| 222 | delete change[prop] |
| 223 | } |
| 224 | } |
| 225 | } |
| 226 | } |
| 227 | return copy |
| 228 | } |