fix(store): move before and fix indent of multiple items
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
c1fe438925
commit
5a7067dc7d
|
@ -214,5 +214,15 @@ describe("A store", function () {
|
|||
expect(debug.idList).toEqual(["_a", "_b", "_c", "_e", "_d"])
|
||||
expect(debug.result[4]).toEqual({text: "d", id: "_d", indented: 0})
|
||||
})
|
||||
it("moveBefore _b, at-end", function () {
|
||||
store.moveBefore("_b", "at-end")
|
||||
let debug = store.debug();
|
||||
expect(debug.idList).toEqual(["_a", "_e", "_b", "_c", "_d"])
|
||||
expect(debug.result[0]).toEqual({text: "a", id: "_a", indented: 0})
|
||||
expect(debug.result[1]).toEqual({text: "e", id: "_e", indented: 0})
|
||||
expect(debug.result[2]).toEqual({text: "b", id: "_b", indented: 0})
|
||||
expect(debug.result[3]).toEqual({text: "c", id: "_c", indented: 1})
|
||||
expect(debug.result[4]).toEqual({text: "d", id: "_d", indented: 2})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -304,10 +304,16 @@ function Store(inputData) {
|
|||
|
||||
// Copy indent from the next item, or 0 when at the end
|
||||
const v = value(to)
|
||||
if (v) value(from).indented = v.indented
|
||||
else value(from).indented = 0
|
||||
const diff = (v ? v.indented : 0) - value(from).indented
|
||||
|
||||
return [index(from), n]
|
||||
let first = index(from)
|
||||
let i = 0
|
||||
while (i < n) {
|
||||
value(idList[first+i]).indented += diff
|
||||
i++
|
||||
}
|
||||
|
||||
return [first, n]
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue
Block a user