Problem: moving up from closed item, moved too far
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Solution: add tests for this problem, and remove indent code when moving up
This commit is contained in:
parent
f617dd973f
commit
79aba57dcb
|
@ -47,4 +47,58 @@ describe("A cursor", function() {
|
|||
expect(this.cursor.get()).toBe(3)
|
||||
})
|
||||
})
|
||||
|
||||
describe("with a store with current closed", function () {
|
||||
beforeEach(function () {
|
||||
this.store = createStore([
|
||||
{indented:0, fold: 'open'},
|
||||
{indented:1, fold: 'open'},
|
||||
{indented:2, fold: 'open'},
|
||||
{indented:3, fold: 'open'},
|
||||
{indented:1, fold: 'closed', hidden: true},
|
||||
])
|
||||
})
|
||||
|
||||
it("moveUp moves up by one", function() {
|
||||
this.cursor.set(4)
|
||||
this.cursor.moveUp(this.store)
|
||||
expect(this.cursor.get()).toBe(3)
|
||||
})
|
||||
})
|
||||
|
||||
describe("with a store with above closed", function () {
|
||||
beforeEach(function () {
|
||||
this.store = createStore([
|
||||
{indented:0, fold: 'open'},
|
||||
{indented:1, fold: 'open'},
|
||||
{indented:2, fold: 'open'},
|
||||
{indented:3, fold: 'closed', hidden: true},
|
||||
{indented:1, fold: 'open'},
|
||||
])
|
||||
})
|
||||
|
||||
it("moveUp moves up by one", function() {
|
||||
this.cursor.set(4)
|
||||
this.cursor.moveUp(this.store)
|
||||
expect(this.cursor.get()).toBe(2)
|
||||
})
|
||||
})
|
||||
|
||||
describe("with a store with multiple above closed", function () {
|
||||
beforeEach(function () {
|
||||
this.store = createStore([
|
||||
{indented:0, fold: 'open'},
|
||||
{indented:1, fold: 'open'},
|
||||
{indented:2, fold: 'closed', hidden: true},
|
||||
{indented:3, fold: 'closed', hidden: true},
|
||||
{indented:1, fold: 'open'},
|
||||
])
|
||||
})
|
||||
|
||||
it("moveUp moves up by one", function() {
|
||||
this.cursor.set(4)
|
||||
this.cursor.moveUp(this.store)
|
||||
expect(this.cursor.get()).toBe(1)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -55,21 +55,15 @@ function Store(inputData) {
|
|||
}
|
||||
|
||||
function prevCursorPosition(cursor) {
|
||||
let curIndent = values[idList[cursor]].indented
|
||||
let curClosed = values[idList[cursor]].fold !== 'open';
|
||||
if (!curClosed) {
|
||||
curIndent = 10000000;
|
||||
}
|
||||
let moving = true
|
||||
|
||||
while (moving) {
|
||||
cursor--
|
||||
if (cursor < 0) {
|
||||
cursor = idList.length - 1
|
||||
curIndent = values[idList[cursor]].indented
|
||||
}
|
||||
let next = values[idList[cursor]];
|
||||
if (curIndent >= next.indented && !next.hidden) {
|
||||
if (!next.hidden) {
|
||||
moving = false
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user