diff --git a/list-editor/spec/cursor.spec.js b/list-editor/spec/cursor.spec.js index eee473d..cb5d31c 100644 --- a/list-editor/spec/cursor.spec.js +++ b/list-editor/spec/cursor.spec.js @@ -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) + }) + }) }) diff --git a/list-editor/store.js b/list-editor/store.js index ab61ef1..0e4bed1 100644 --- a/list-editor/store.js +++ b/list-editor/store.js @@ -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 } }