(id:string, text:string, packed:any[], attributes:{[id:string]: any|undefined})
| 770 | |
| 771 | // This is a new document and we need to rebuild it from scratch. |
| 772 | loadDocument(id:string, text:string, packed:any[], attributes:{[id:string]: any|undefined}) { |
| 773 | // Reset history and suppress storing the load as a history step. |
| 774 | this.history.position = 0; |
| 775 | this.history.items = []; |
| 776 | this.history.transitioning = true; |
| 777 | |
| 778 | if(packed.length % 4 !== 0) throw new Error("Invalid span packing, unable to load."); |
| 779 | this.cm.operation(() => { |
| 780 | this.reloading = true; |
| 781 | |
| 782 | // this is a new document and we need to rebuild it from scratch. |
| 783 | this.cm.setValue(text); |
| 784 | let doc = this.cm.getDoc(); |
| 785 | |
| 786 | for(let i = 0; i < packed.length; i += 4) { |
| 787 | let from = doc.posFromIndex(packed[i]); |
| 788 | let to = doc.posFromIndex(packed[i + 1]); |
| 789 | let type = packed[i + 2]; |
| 790 | let id = packed[i + 3]; |
| 791 | |
| 792 | //console.info(type, debugTokenWithContext(text, packed[i], packed[i + 1])); |
| 793 | |
| 794 | let source = attributes[id] || {}; |
| 795 | source.type = type; |
| 796 | source.id = id; |
| 797 | this.markSpan(from, to, source); |
| 798 | } |
| 799 | }); |
| 800 | this.reloading = false; |
| 801 | this.history.transitioning = false; |
| 802 | this.dirty = false; |
| 803 | this._md = undefined; |
| 804 | } |
| 805 | |
| 806 | // This is an update to an existing document, so we need to figure out what got added and removed. |
| 807 | updateDocument(packed:any[], attributes:{[id:string]: any|undefined}) { |
nothing calls this directly
no test coverage detected