Save folds closed/open status in localStorage
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Peter Stuifzand 2021-09-25 20:59:50 +02:00
parent e98a099127
commit f8a94455cd
2 changed files with 19 additions and 2 deletions

View File

@ -320,9 +320,12 @@ function editor(root, inputData, options) {
let hideLevel = 99999; let hideLevel = 99999;
let closedFolds = JSON.parse(localStorage.getItem('closed-folds') || '{}') || {}
$enter.each(function (index, li) { $enter.each(function (index, li) {
let storeId = enterData[index] let storeId = enterData[index]
let value = rootData.value(storeId) let value = rootData.value(storeId)
value.fold = closedFolds[value.id] ? 'closed' : 'open'
let hasChildren = false; let hasChildren = false;
if (index + 1 < last) { if (index + 1 < last) {
@ -358,6 +361,8 @@ function editor(root, inputData, options) {
_.each(exitData, function (storeId, index) { _.each(exitData, function (storeId, index) {
let value = rootData.value(storeId) let value = rootData.value(storeId)
value.fold = closedFolds[value.id] ? 'closed' : 'open'
let $li = newItem(value) let $li = newItem(value)
.css('margin-left', (value.indented * 32) + 'px') .css('margin-left', (value.indented * 32) + 'px')
.toggleClass('selected', cursor.atPosition(index + $enter.length)) .toggleClass('selected', cursor.atPosition(index + $enter.length))
@ -427,6 +432,7 @@ function editor(root, inputData, options) {
let newPosition = store.moveBefore(startID, stopID) let newPosition = store.moveBefore(startID, stopID)
cursor.set(newPosition[0]) cursor.set(newPosition[0])
// fix indent
_.defer(() => { _.defer(() => {
trigger('change') trigger('change')

View File

@ -203,9 +203,20 @@ function Store(inputData) {
values[currentId] = newValue values[currentId] = newValue
changed = true changed = true
} }
updateFold(currentId, newValue.fold === 'open')
return currentId return currentId
} }
function updateFold(id, open) {
let closedFolds = JSON.parse(localStorage.getItem("closed-folds") || '{}') || {}
if (!open) {
closedFolds[id] = true
} else {
delete closedFolds[id]
}
localStorage.setItem('closed-folds', JSON.stringify(closedFolds))
}
function length() { function length() {
return idList.length; return idList.length;
} }