Skip to content

Save and restore the code folding state #5485

Answered by Syone
Syone asked this question in Q&A
Discussion options

You must be logged in to vote

No it doesn't work but I found a solution, when I retrieve folds using editor.session.getAllFolds() subfolds start/end coordinates are relative to their parent fold. And when we add a subfold into another fold using f.addSubFold(subfold) we have to use "absolute coordinates".
So what I have to do is to recalculate each subfold coordinates before storing it:

	// Save all folds in local storage
	localStorage.setItem(id, JSON.stringify(getFolds(editor.session.getAllFolds())));
	function getFolds(folds, row = 0) {
		if (folds.length === 0) return [];
		let res = [];
		folds.forEach(function (fold) {
			res.push({
				start: {row: fold.start.row + row, column: fold.start.column},
				end: {row: 

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Syone
Comment options

Answer selected by Syone
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants