{"record":{"id":"dec8346138c89d31","repo":"ajaxorg/ace","slug":"can-t-add-a-fold-to-this-foldline-as-it-has-no-con","errorCode":null,"errorMessage":"Can't add a fold to this FoldLine as it has no connection","messagePattern":"Can't add a fold to this FoldLine as it has no connection","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/edit_session/fold_line.js","lineNumber":53,"sourceCode":"     * @param {number} shift\n     */\n    shiftRow(shift) {\n        this.start.row += shift;\n        this.end.row += shift;\n        this.folds.forEach(function(fold) {\n            fold.start.row += shift;\n            fold.end.row += shift;\n        });\n    }\n\n    /**\n     * @param {Fold} fold\n     */\n    addFold(fold) {\n        if (fold.sameRow) {\n            // @ts-expect-error TODO: startRow, endRow are missing in Fold and FoldLine\n            if (fold.start.row < this.startRow || fold.endRow > this.endRow) {\n                throw new Error(\"Can't add a fold to this FoldLine as it has no connection\");\n            }\n            this.folds.push(fold);\n            this.folds.sort(function(a, b) {\n                return -a.range.compareEnd(b.start.row, b.start.column);\n            });\n            if (this.range.compareEnd(fold.start.row, fold.start.column) > 0) {\n                this.end.row = fold.end.row;\n                this.end.column =  fold.end.column;\n            } else if (this.range.compareStart(fold.end.row, fold.end.column) < 0) {\n                this.start.row = fold.start.row;\n                this.start.column = fold.start.column;\n            }\n        } else if (fold.start.row == this.end.row) {\n            this.folds.push(fold);\n            this.end.row = fold.end.row;\n            this.end.column = fold.end.column;\n        } else if (fold.end.row == this.start.row) {\n            this.folds.unshift(fold);","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/ajaxorg/ace/blob/2c1eddc392eb92cf222a4478f1893d2b2c354fb0/src/edit_session/fold_line.js#L35-L71","documentation":"FoldLine.addFold() only accepts a fold whose start/end rows fall within this FoldLine's row span when the fold is sameRow. A fold outside the FoldLine's range means internal fold/bookkeeping state is inconsistent, so Ace throws to prevent corrupting the fold structure.","triggerScenarios":"Calling editSession.addFold/addUntitledFold with a range that spans rows incorrectly merged, or programmatic fold manipulation while the session's fold lines are stale (e.g. after external edits without proper change notification).","commonSituations":"Plugins or custom folding code adding folds manually; editing text via low-level APIs that bypass session document change events; merging fold lines during concurrent edits.","solutions":["Only add folds via editSession.addFold with a range within a single line, or spanning rows handled by the FoldLine merge logic","Re-fetch/refresh fold structures after external edits rather than caching FoldLine objects","Use the built-in folding mode APIs instead of constructing Fold/FoldLine manually"],"exampleFix":"// before\nvar foldLine = session.foldLines[0];\nfoldLine.addFold(fold); // fold rows outside foldLine\n// after\nsession.addFold('...', new AceRange(0, 5, 0, 10)); // let session manage FoldLines","handlingStrategy":"try-catch","validationCode":"// Ensure folds are added through the session, not FoldLine directly\n// and check row containment first:\nif (fold.start.row < foldLine.startRow || fold.end.row > foldLine.endRow) {\n  throw new Error('fold outside fold line');\n}","typeGuard":"function canAddTo(foldLine, fold) { return fold.start.row >= foldLine.startRow && fold.end.row <= foldLine.endRow; }","tryCatchPattern":"try { session.addFold('...', range); } catch (e) { if (/no connection|matching row/.test(e.message)) { session.unfold(range, true); session.addFold('...', range); } else throw e; }","preventionTips":["Always use editSession.addFold/unfold APIs","Don't cache FoldLine references across edits","Unfold before re-folding mutated regions"],"tags":["folding","internal-state"],"backgroundTag":"invalid-fold-operation","analyzedSha":"2c1eddc392eb92cf222a4478f1893d2b2c354fb0","analyzedAt":"2026-08-30T00:39:52.222Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}