From bf27f5bdfb73d8ed75b3dbf304ddcdcff57c5908 Mon Sep 17 00:00:00 2001 From: tnrich Date: Mon, 16 Nov 2015 11:57:46 -0800 Subject: [PATCH 01/15] fixes inverting a circular range and add tests for it --- app/cerebral/actions/selectInverse.js | 9 ++--- app/ve-range-utils/invertCircularRange.js | 10 +++++ .../invertCircularRange.test.js | 38 +++++++++++++++++++ 3 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 app/ve-range-utils/invertCircularRange.js create mode 100644 app/ve-range-utils/invertCircularRange.test.js diff --git a/app/cerebral/actions/selectInverse.js b/app/cerebral/actions/selectInverse.js index 10450cb88..0f7bd7729 100644 --- a/app/cerebral/actions/selectInverse.js +++ b/app/cerebral/actions/selectInverse.js @@ -1,11 +1,8 @@ +var invertCircularRange = require('ve-range-utils/invertCircularRange'); export default function selectInverse(input, tree, output) { //compare the sequenceString being pasted in with what's already stored in the clipboard - var selectionLayer = tree.get(['selectionLayer']); - + var {selectionLayer, sequenceLength} = tree.get(); output({ - selectionLayer: { - start: selectionLayer.end, - end: selectionLayer.start - 1 - } + selectionLayer: invertCircularRange(selectionLayer, sequenceLength) }); } \ No newline at end of file diff --git a/app/ve-range-utils/invertCircularRange.js b/app/ve-range-utils/invertCircularRange.js new file mode 100644 index 000000000..1a669d6c1 --- /dev/null +++ b/app/ve-range-utils/invertCircularRange.js @@ -0,0 +1,10 @@ +require('chai').should() +var normalizePositionByRangeLength = require('./normalizePositionByRangeLength'); +module.exports = function invertCircularRange(range, rangeMax) { + var start = range.end + 1; + var end = range.start - 1; + return { + start: normalizePositionByRangeLength(start, rangeMax, false), + end: normalizePositionByRangeLength(end, rangeMax, false), + } +} \ No newline at end of file diff --git a/app/ve-range-utils/invertCircularRange.test.js b/app/ve-range-utils/invertCircularRange.test.js new file mode 100644 index 000000000..0b746dec0 --- /dev/null +++ b/app/ve-range-utils/invertCircularRange.test.js @@ -0,0 +1,38 @@ +var invertCircularRange = require('./invertCircularRange'); +describe('invertCircularRange', function () { + it('should invert a non-circular range', function () { + var invertedRange = invertCircularRange({start: 2, end:2}, 10); + invertedRange.start.should.equal(3) + invertedRange.end.should.equal(1) + }); + it('should invert a non-circular range', function () { + var invertedRange = invertCircularRange({start: 0, end:2}, 10); + invertedRange.start.should.equal(3) + invertedRange.end.should.equal(9) + }); + it('should invert a non-circular range', function () { + var invertedRange = invertCircularRange({start: 0, end:9}, 10); + invertedRange.start.should.equal(0) + invertedRange.end.should.equal(9) + }); + it('should invert a non-circular range', function () { + var invertedRange = invertCircularRange({start: 4, end:9}, 10); + invertedRange.start.should.equal(0) + invertedRange.end.should.equal(3) + }); + it('should invert a circular range', function () { + var invertedRange = invertCircularRange({start: 3, end:1}, 10); + invertedRange.start.should.equal(2) + invertedRange.end.should.equal(2) + }); + it('should invert a circular range', function () { + var invertedRange = invertCircularRange({start: 9, end:1}, 10); + invertedRange.start.should.equal(2) + invertedRange.end.should.equal(8) + }); + it('should invert a circular range', function () { + var invertedRange = invertCircularRange({start: 3, end:0}, 10); + invertedRange.start.should.equal(1) + invertedRange.end.should.equal(2) + }); +}); \ No newline at end of file From 90e540b46cf4393fe459d29ebcafcf0628a55ed3 Mon Sep 17 00:00:00 2001 From: tnrich Date: Mon, 16 Nov 2015 11:58:24 -0800 Subject: [PATCH 02/15] adds resizer to circular view caret --- app/CircularView.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/CircularView.js b/app/CircularView.js index c9a9a6452..6c86b4c01 100644 --- a/app/CircularView.js +++ b/app/CircularView.js @@ -266,7 +266,7 @@ function Caret ({caretPosition, sequenceLength, innerRadius, outerRadius}) { eAngle={ endAngle } height={ 0 }> Date: Mon, 16 Nov 2015 11:58:59 -0800 Subject: [PATCH 03/15] working on fixing drag logic, need to add more tests --- .../actions/handleEditorDragStopped.js | 5 ++- app/cerebral/actions/handleEditorDragged.js | 41 ++++++++++--------- app/cerebral/signals.js | 6 +++ app/cerebral/signals/editorDragged.test.js | 3 +- 4 files changed, 34 insertions(+), 21 deletions(-) diff --git a/app/cerebral/actions/handleEditorDragStopped.js b/app/cerebral/actions/handleEditorDragStopped.js index 2b38d18bb..40531ea23 100644 --- a/app/cerebral/actions/handleEditorDragStopped.js +++ b/app/cerebral/actions/handleEditorDragStopped.js @@ -1,4 +1,7 @@ var ac = require('ve-api-check/apiCheck'); export default function handleEditorDragStopped(input, tree) { - tree.set(['editorDrag', 'inProgress'], false) + // setTimeout(function() { + console.log('something cray: '); + tree.set(['editorDrag', 'inProgress'], false) + // }, 0); } \ No newline at end of file diff --git a/app/cerebral/actions/handleEditorDragged.js b/app/cerebral/actions/handleEditorDragged.js index 64da416ba..e575323cc 100644 --- a/app/cerebral/actions/handleEditorDragged.js +++ b/app/cerebral/actions/handleEditorDragged.js @@ -1,5 +1,6 @@ // var trimNumberToFitWithin0ToAnotherNumber = require('ve-range-utils/trimNumberToFitWithin0ToAnotherNumber'); -// var normalizePositionByRangeLength = require('ve-range-utils/normalizePositionByRangeLength'); +var normalizePositionByRangeLength = require('ve-range-utils/normalizePositionByRangeLength'); +var getRangeLength = require('ve-range-utils/getRangeLength'); // var ac = require('ve-api-check'); export default function handleEditorDragged({ nearestBP, @@ -10,38 +11,40 @@ export default function handleEditorDragged({ }, editorDrag: {fixedCaretPositionOnDragStart, fixedCaretPositionOnDragStartType} } = tree.get(); tree.set(['editorDrag', 'inProgress'], true) - if (nearestBP === fixedCaretPositionOnDragStart) { + if (nearestBP === fixedCaretPositionOnDragStart && (!selectionLayer.selected || getRangeLength(selectionLayer) < 2)) { output.caretMoved({ caretPosition: fixedCaretPositionOnDragStart }); } else { var newSelectionLayer; - if (fixedCaretPositionOnDragStartType === 'start') { + if (fixedCaretPositionOnDragStartType === 'start' && circular) { newSelectionLayer = { start: fixedCaretPositionOnDragStart, - end: nearestBP - 1, + end: normalizePositionByRangeLength(nearestBP - 1, sequenceLength, true), cursorAtEnd: true, }; - } else if (fixedCaretPositionOnDragStartType === 'end') { + } else if (fixedCaretPositionOnDragStartType === 'end' && circular) { newSelectionLayer = { start: nearestBP, - end: fixedCaretPositionOnDragStart - 1, + end: normalizePositionByRangeLength(fixedCaretPositionOnDragStart - 1, sequenceLength, true), cursorAtEnd: false, }; } else { - if (nearestBP > fixedCaretPositionOnDragStart) { - newSelectionLayer = { - start: fixedCaretPositionOnDragStart, - end: nearestBP - 1, - cursorAtEnd: true, - }; - } else { - newSelectionLayer = { - start: nearestBP, - end: fixedCaretPositionOnDragStart - 1, - cursorAtEnd: false, - }; - } + if (nearestBP > fixedCaretPositionOnDragStart) { + newSelectionLayer = { + start: fixedCaretPositionOnDragStart, + end: nearestBP - 1, + cursorAtEnd: true, + }; + tree.set(['editorDrag', 'fixedCaretPositionOnDragStartType'], 'start') + } else { + newSelectionLayer = { + start: nearestBP, + end: fixedCaretPositionOnDragStart - 1, + cursorAtEnd: false, + }; + tree.set(['editorDrag', 'fixedCaretPositionOnDragStartType'], 'end') + } } output.selectionUpdated({ selectionLayer: newSelectionLayer diff --git a/app/cerebral/signals.js b/app/cerebral/signals.js index 4eed36df3..5b3115368 100644 --- a/app/cerebral/signals.js +++ b/app/cerebral/signals.js @@ -68,6 +68,12 @@ export default function(controller, options) { a.handleEditorDragStarted ], editorDragStopped: [ + [function pause (input, tree, output) { + //async function that doesn't do anything + setTimeout(function () { + output() + },0) + }], a.handleEditorDragStopped ], //tnr: NOT YET WORKING: diff --git a/app/cerebral/signals/editorDragged.test.js b/app/cerebral/signals/editorDragged.test.js index 8460f66fd..8513a5905 100644 --- a/app/cerebral/signals/editorDragged.test.js +++ b/app/cerebral/signals/editorDragged.test.js @@ -100,7 +100,7 @@ describe('editorDragged circular sequence', function() { }) controller.signals.editorDragStopped(); }); - it.skip('editorDrag starts by grabbing caret at pos 1 and moves around the sequence', function(done) { + it.only('editorDrag starts by grabbing caret at pos 1 and moves around the sequence', function(done) { var controller = require('../controller')({ //instantiate some default val's here: state: { @@ -116,6 +116,7 @@ describe('editorDragged circular sequence', function() { }); controller.signals.editorDragStarted({nearestBP: 1, caretGrabbed: true}); controller.signals.editorDragged({nearestBP: 0}); + debugger; testSignal(controller.signals.editorDragged, { nearestBP: 1, }, function() { From 8ece949c716118f305625852f7226dbcac73265c Mon Sep 17 00:00:00 2001 From: tnrich Date: Mon, 16 Nov 2015 23:17:00 -0800 Subject: [PATCH 04/15] improve action factory that checks booleans --- app/cerebral/actions/checkBooleanState.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/cerebral/actions/checkBooleanState.js b/app/cerebral/actions/checkBooleanState.js index 3854c69ae..8dc86c7dc 100644 --- a/app/cerebral/actions/checkBooleanState.js +++ b/app/cerebral/actions/checkBooleanState.js @@ -9,6 +9,6 @@ module.exports = function checkBooleanState(path) { output.error() } } - stateCheck.displayName = 'checkBooleanState' + path.toString(); + stateCheck.displayName = 'checkBooleanState: [' + path.toString() + ']'; return stateCheck; } \ No newline at end of file From fd67edcbeecfe6f78f80d8ef00dc366228544ed8 Mon Sep 17 00:00:00 2001 From: tnrich Date: Mon, 16 Nov 2015 23:18:13 -0800 Subject: [PATCH 05/15] fix click events --- app/SequenceEditor.js | 97 ------------------- .../actions/createSelectionShiftClick.js | 12 +-- .../actions/updateSelectionShiftClick.js | 8 +- 3 files changed, 10 insertions(+), 107 deletions(-) diff --git a/app/SequenceEditor.js b/app/SequenceEditor.js index 5e1843ea6..b361c4284 100644 --- a/app/SequenceEditor.js +++ b/app/SequenceEditor.js @@ -131,103 +131,6 @@ class SequenceEditor extends React.Component { // Remove any Mousetrap bindings before unmounting.detach() combokeys.detach() } - - // handleEditorClick({nearestBP, shiftHeld}) { - // //if cursor position is different than the original position, reset the position and clear the selection - // if (this.editorBeingDragged) { - // //do nothing because the click was triggered by a drag event - // } else { - // this.props.signals.editorClicked({ - // shiftHeld, - // type: 'editorClick', - // updatedCaretPos: nearestBP - // }) - // } - // } - - // handleEditorDrag({nearestBP}) { - // var { - // setCaretPosition, - // setSelectionLayer - // } = this.props.signals; - // //note this method relies on variables that are set in the handleEditorDragStart method! - // this.editorBeingDragged = true; - // console.log('nearestBP: ' + JSON.stringify(nearestBP,null,4)); - // if (nearestBP === this.fixedCaretPositionOnEditorDragStart) { - // setCaretPosition(nearestBP); - // setSelectionLayer(false); - // } else { - // var newSelectionLayer; - // if (this.fixedCaretPositionOnEditorDragStartType === 'start') { - // newSelectionLayer = { - // start: this.fixedCaretPositionOnEditorDragStart, - // end: nearestBP - 1, - // cursorAtEnd: true, - // }; - // } else if (this.fixedCaretPositionOnEditorDragStartType === 'end') { - // newSelectionLayer = { - // start: nearestBP, - // end: this.fixedCaretPositionOnEditorDragStart - 1, - // cursorAtEnd: false, - // }; - // } else { - // if (nearestBP > this.fixedCaretPositionOnEditorDragStart) { - // newSelectionLayer = { - // start: this.fixedCaretPositionOnEditorDragStart, - // end: nearestBP - 1, - // cursorAtEnd: true, - // }; - // } else { - // newSelectionLayer = { - // start: nearestBP, - // end: this.fixedCaretPositionOnEditorDragStart - 1, - // cursorAtEnd: false, - // }; - // } - // } - // setSelectionLayer({selectionLayer: newSelectionLayer}); - // } - // } - - // handleEditorDragStart({nearestBP, caretGrabbed}) { - // var {selectionLayer} = this.props; - // if (caretGrabbed && selectionLayer.selected) { - // // this.circularSelectionOnEditorDragStart = (selectionLayer.start > selectionLayer.end); - // if (selectionLayer.start === nearestBP) { - // this.fixedCaretPositionOnEditorDragStart = selectionLayer.end + 1; - // this.fixedCaretPositionOnEditorDragStartType = 'end'; - - // //plus one because the cursor position will be 1 more than the selectionLayer.end - // //imagine selection from - // //0 1 2 <--possible cursor positions - // // A T G - // //if A is selected, selection.start = 0, selection.end = 0 - // //so the nearestBP for the end of the selection is 1! - // //which is selection.end+1 - // } else { - // this.fixedCaretPositionOnEditorDragStart = selectionLayer.start; - // this.fixedCaretPositionOnEditorDragStartType = 'start'; - // } - // } else { - // // this.circularSelectionOnEditorDragStart = false; - // this.fixedCaretPositionOnEditorDragStart = nearestBP; - // this.fixedCaretPositionOnEditorDragStartType = 'caret'; - // } - // } - - // handleEditorDragStop(event, ui) { - // var self = this; - // if (this.editorBeingDragged) { //check to make sure dragging actually occurred - // setTimeout(function() { - // //we use setTimeout to put the call to change editorBeingDragged to false - // //on the bottom of the event stack, thus the click event that is fired because of the drag - // //will be able to check if editorBeingDragged and not trigger if it is - // self.editorBeingDragged = false; - // }, 0); - // } else { - // self.editorBeingDragged = false; - // } - // } render() { var { selectedSequenceString, diff --git a/app/cerebral/actions/createSelectionShiftClick.js b/app/cerebral/actions/createSelectionShiftClick.js index c26f28423..a9aca9497 100644 --- a/app/cerebral/actions/createSelectionShiftClick.js +++ b/app/cerebral/actions/createSelectionShiftClick.js @@ -1,17 +1,17 @@ export default function createSelectionShiftClick({ - updatedCaretPos, caretPosition + nearestBP, caretPosition }, tree, output) { var ac = require('ve-api-check'); - ac.throw(ac.posInt, updatedCaretPos) + ac.throw(ac.posInt, nearestBP) ac.throw(ac.posInt, caretPosition) - if (updatedCaretPos === caretPosition) { + if (nearestBP === caretPosition) { return output.doNothing() } - if (updatedCaretPos > caretPosition) { + if (nearestBP > caretPosition) { output.updateSelection({ selectionLayer: { start: caretPosition, - end: updatedCaretPos - 1, + end: nearestBP - 1, cursorAtEnd: true, selected: true } @@ -19,7 +19,7 @@ export default function createSelectionShiftClick({ } else { output.updateSelection({ selectionLayer: { - start: updatedCaretPos, + start: nearestBP, end: caretPosition - 1, cursorAtEnd: false, selected: true diff --git a/app/cerebral/actions/updateSelectionShiftClick.js b/app/cerebral/actions/updateSelectionShiftClick.js index 2daf98a36..6411563ab 100644 --- a/app/cerebral/actions/updateSelectionShiftClick.js +++ b/app/cerebral/actions/updateSelectionShiftClick.js @@ -1,14 +1,14 @@ var expandOrContractNonCircularRangeToPosition = require('ve-range-utils/expandOrContractNonCircularRangeToPosition'); var expandOrContractCircularRangeToPosition = require('ve-range-utils/expandOrContractCircularRangeToPosition'); var ac = require('ve-api-check'); -export default function updateSelectionShiftClick({updatedCaretPos, sequenceLength, caretPosition, selectionLayer}, tree, output) { - if (selectionLayer.start > selectionLayer.end) { - var {newRange, endMoved} = expandOrContractCircularRangeToPosition(selectionLayer, updatedCaretPos, sequenceLength); +export default function updateSelectionShiftClick({nearestBP, sequenceLength, caretPosition, selectionLayer}, tree, output) { + if (true || selectionLayer.start > selectionLayer.end) { + var {newRange, endMoved} = expandOrContractCircularRangeToPosition(selectionLayer, nearestBP, sequenceLength); newRange.cursorAtEnd = endMoved; output({selectionLayer: newRange}) } else { /*eslint-disable no-redeclare*/ - var {newRange, endMoved} = expandOrContractNonCircularRangeToPosition(selectionLayer, updatedCaretPos); + var {newRange, endMoved} = expandOrContractNonCircularRangeToPosition(selectionLayer, nearestBP); /*eslint-enable no-redeclare*/ newRange.cursorAtEnd = endMoved; output({selectionLayer: newRange}) From c34d009ac23f3cb5de2a8193770ab165022c0cfa Mon Sep 17 00:00:00 2001 From: tnrich Date: Mon, 16 Nov 2015 23:23:50 -0800 Subject: [PATCH 06/15] fixing drag signal handling and adding more tests --- app/cerebral/actions/handleEditorDragged.js | 2 +- app/cerebral/controller.js | 49 ++++-- app/cerebral/signals/caretMoved.test.js | 73 ++++---- app/cerebral/signals/editorDragged.test.js | 185 +++++++------------- app/cerebral/testSignal.js | 21 ++- 5 files changed, 145 insertions(+), 185 deletions(-) diff --git a/app/cerebral/actions/handleEditorDragged.js b/app/cerebral/actions/handleEditorDragged.js index e575323cc..9779a3789 100644 --- a/app/cerebral/actions/handleEditorDragged.js +++ b/app/cerebral/actions/handleEditorDragged.js @@ -11,7 +11,7 @@ export default function handleEditorDragged({ }, editorDrag: {fixedCaretPositionOnDragStart, fixedCaretPositionOnDragStartType} } = tree.get(); tree.set(['editorDrag', 'inProgress'], true) - if (nearestBP === fixedCaretPositionOnDragStart && (!selectionLayer.selected || getRangeLength(selectionLayer) < 2)) { + if (nearestBP === fixedCaretPositionOnDragStart && (!selectionLayer.selected || selectionLayer.start < selectionLayer.end)) { output.caretMoved({ caretPosition: fixedCaretPositionOnDragStart }); diff --git a/app/cerebral/controller.js b/app/cerebral/controller.js index 3154b4f15..7abab1e50 100644 --- a/app/cerebral/controller.js +++ b/app/cerebral/controller.js @@ -6,24 +6,39 @@ import assign from 'lodash/object/assign' var tidyUpSequenceData = require('ve-sequence-utils/tidyUpSequenceData'); -export default function (options={state: null, services: null, actions: null}) { - //merge all optional state into the default state - var newDefaultState = assign({},defaultState, options.state); - //tidy up the sequence data so it will work in our app - newDefaultState.sequenceData = tidyUpSequenceData(newDefaultState.sequenceData) +export default function(options = { + state: null, + services: null, + actions: null +}) { + //merge all optional state into the default state + var newDefaultState = assign({}, defaultState, options.state); + //tidy up the sequence data so it will work in our app + newDefaultState.sequenceData = tidyUpSequenceData(newDefaultState.sequenceData) - //tnr: we can pass extra baobab-specific options here as well if we want - const model = Model(newDefaultState); - - //tnr: services are things like an ajax library, or some default values that we want every action to have access to - const services = {}; - //create the controller - var controller = Controller(model, services); + //tnr: we can pass extra baobab-specific options here as well if we want + const model = Model(newDefaultState); - controller.tree = model.tree; + //tnr: services are things like an ajax library, or some default values that we want every action to have access to + const services = {}; + //create the controller + var controller = Controller(model, services); + // only when testing - expose the model on the controller + // (webpack will make process.env.NODE_ENV available). + if (process.env.NODE_ENV === 'testing') { + // DON'T DO THIS IN PRODUCTION + controller.model = model; + controller.tree = model.tree; - //and attach signals to it - signals(controller, options); - return controller; -} + // optional test helper to rest cerebral state, you may want to put this + // somewhere else if don't like test methods being deployed to production. + controller.reset = function() { + model.tree.set(newDefaultState); + model.tree.commit(); + }; + } + //and attach signals to it + signals(controller, options); + return controller; +} \ No newline at end of file diff --git a/app/cerebral/signals/caretMoved.test.js b/app/cerebral/signals/caretMoved.test.js index 21a8a48a3..0151f1301 100644 --- a/app/cerebral/signals/caretMoved.test.js +++ b/app/cerebral/signals/caretMoved.test.js @@ -10,9 +10,9 @@ var controller = require('../controller')({ circular: true }, bpsPerRow: 2 //override the usual calc here - //seq looks like: - //at - //at + //seq looks like: + //at + //at } }); @@ -20,110 +20,103 @@ var testSignal = require('../testSignal'); var caretMoved = controller.signals.caretMoved; describe('caretMoved circular sequence', function() { - beforeEach(function () { + beforeEach(function() { + controller.reset(); controller.tree.set(['sequenceData', 'circular'], true); }) - it('moveCaretLeftOne should move the cursor left 1', function(done) { + it('moveCaretLeftOne should move the cursor left 1', function() { controller.tree.set('caretPosition', 1); - testSignal(caretMoved, { + return testSignal(controller, caretMoved, { type: 'moveCaretLeftOne', shiftHeld: false, }, function() { controller.get('caretPosition').should.equal(0); - done() }) }); - it('calling moveCaretLeftOne twice should move the cursor left 2 positions and around the sequence', function(done) { + it('calling moveCaretLeftOne twice should move the cursor left 2 positions and around the sequence', function() { controller.tree.set('caretPosition', 1); - controller.signals.caretMoved({ + return testSignal(controller, caretMoved, { type: 'moveCaretLeftOne', shiftHeld: false, - }); - testSignal(caretMoved, { - type: 'moveCaretLeftOne', - shiftHeld: false, - }, function() { - controller.get('caretPosition').should.equal(3); - done() + }).then(function() { + return testSignal(controller, caretMoved, { + type: 'moveCaretLeftOne', + shiftHeld: false, + }, function() { + controller.get('caretPosition').should.equal(3); + }) }) }); - - it('moveCaretRightOne should move the cursor right 1', function(done) { + + it('moveCaretRightOne should move the cursor right 1', function() { controller.tree.set('caretPosition', 1); - testSignal(caretMoved, { + return testSignal(controller, caretMoved, { type: 'moveCaretRightOne', shiftHeld: false, }, function() { controller.get('caretPosition').should.equal(2); - done() }) }); - it('moveCaretRightOne should move the cursor right 1 and around the sequence', function(done) { + it('moveCaretRightOne should move the cursor right 1 and around the sequence', function() { controller.tree.set('caretPosition', 4); - testSignal(caretMoved, { + return testSignal(controller, caretMoved, { type: 'moveCaretRightOne', shiftHeld: false, }, function() { controller.get('caretPosition').should.equal(1); - done() }) }); - it('moveCaretUpARow should move the cursor up 2 places', function(done) { + it('moveCaretUpARow should move the cursor up 2 places', function() { controller.tree.set('caretPosition', 4); - testSignal(caretMoved, { + return testSignal(controller, caretMoved, { type: 'moveCaretUpARow', shiftHeld: false, }, function() { controller.get('caretPosition').should.equal(2); - done() }) }); - it('moveCaretUpARow should move the cursor up 2 places and around the sequence', function(done) { + it('moveCaretUpARow should move the cursor up 2 places and around the sequence', function() { controller.tree.set('caretPosition', 0); - testSignal(caretMoved, { + return testSignal(controller, caretMoved, { type: 'moveCaretUpARow', shiftHeld: false, }, function() { controller.get('caretPosition').should.equal(2); - done() }) }); }); describe('caretMoved non circular sequence', function() { - beforeEach(function () { + beforeEach(function() { controller.tree.set(['sequenceData', 'circular'], false); }) - it('moveCaretLeftOne should not move the cursor around the sequence', function(done) { + it('moveCaretLeftOne should not move the cursor around the sequence', function() { controller.tree.set('caretPosition', 0); - testSignal(caretMoved, { + return testSignal(controller, caretMoved, { type: 'moveCaretLeftOne', shiftHeld: false, }, function() { controller.get('caretPosition').should.equal(0); - done() }) }); - - it('moveCaretRightOne should not move the cursor around the sequence', function(done) { + + it('moveCaretRightOne should not move the cursor around the sequence', function() { controller.tree.set('caretPosition', 4); - testSignal(caretMoved, { + return testSignal(controller, caretMoved, { type: 'moveCaretRightOne', shiftHeld: false, }, function() { controller.get('caretPosition').should.equal(4); - done() }) }); - it('moveCaretUpARow should move the cursor up 2 places and around the sequence', function(done) { + it('moveCaretUpARow should move the cursor up 2 places and around the sequence', function() { controller.tree.set('caretPosition', 0); - testSignal(caretMoved, { + return testSignal(controller, caretMoved, { type: 'moveCaretUpARow', shiftHeld: false, }, function() { controller.get('caretPosition').should.equal(0); - done() }) }); }); \ No newline at end of file diff --git a/app/cerebral/signals/editorDragged.test.js b/app/cerebral/signals/editorDragged.test.js index 8513a5905..ca4c80c52 100644 --- a/app/cerebral/signals/editorDragged.test.js +++ b/app/cerebral/signals/editorDragged.test.js @@ -1,130 +1,73 @@ -var testSignal = require('../testSignal'); +var controller = require('../controller')({ + //instantiate some default val's here: + state: { + selectionLayer: { + selected: false, + }, + caretPosition: 1, + sequenceData: { + sequence: 'atatatatat', + circular: true + }, + } +}); + +var testSignal = require('../testSignal2'); describe('editorDragged circular sequence', function() { - it('editorDrag starts by grabbing caret at pos 1 and moves to 2', function(done) { - var controller = require('../controller')({ - //instantiate some default val's here: - state: { - selectionLayer: { - selected: false, - }, - caretPosition: 1, - sequenceData: { - sequence: 'atatatatat', - circular: true - }, - } - }); - controller.signals.editorDragStarted({nearestBP: 1, caretGrabbed: true}); - testSignal(controller.signals.editorDragged, { - nearestBP: 2, - }, function() { - controller.get('selectionLayer').start.should.equal(1); - controller.get('selectionLayer').end.should.equal(1); - controller.get('caretPosition').should.equal(2); - done() - }) - controller.signals.editorDragStopped(); + beforeEach(function() { + controller.reset(); }); - it('editorDrag starts by grabbing caret at pos 1 and moves to 2 and then moves back to pos 1', function(done) { - var controller = require('../controller')({ - //instantiate some default val's here: - state: { - selectionLayer: { - selected: false, - }, - caretPosition: 1, - sequenceData: { - sequence: 'atatatatat', - circular: true - }, - } - }); - controller.signals.editorDragStarted({nearestBP: 1, caretGrabbed: true}); - controller.signals.editorDragged({nearestBP: 2}); - testSignal(controller.signals.editorDragged, { - nearestBP: 1, - }, function() { - controller.get('selectionLayer').selected.should.equal(false); - controller.get('caretPosition').should.equal(1); - done() + it('editorDrag starts by grabbing caret at pos 1 and moves to 2, 3, 1, 0', function() { + return testSignal(controller, controller.signals.editorDragStarted, {nearestBP: 1, caretGrabbed: true}) + .then(function () { + return testSignal(controller, controller.signals.editorDragged, {nearestBP: 2}, () => { + controller.get('selectionLayer').start.should.equal(1); + controller.get('selectionLayer').end.should.equal(1); + controller.get('caretPosition').should.equal(2); + }); }) - controller.signals.editorDragStopped(); - }); - it('editorDrag starts by grabbing caret at pos 1 and moves to 0', function(done) { - var controller = require('../controller')({ - //instantiate some default val's here: - state: { - selectionLayer: { - selected: false, - }, - caretPosition: 1, - sequenceData: { - sequence: 'atatatatat', - circular: true - }, - } - }); - controller.signals.editorDragStarted({nearestBP: 1, caretGrabbed: true}); - testSignal(controller.signals.editorDragged, { - nearestBP: 0, - }, function() { - controller.get('selectionLayer').start.should.equal(0); - controller.get('selectionLayer').end.should.equal(0); - controller.get('caretPosition').should.equal(0); - done() + .then(function () { + return testSignal(controller, controller.signals.editorDragged, {nearestBP: 3}, () => { + controller.get('selectionLayer').start.should.equal(1); + controller.get('selectionLayer').end.should.equal(2); + controller.get('caretPosition').should.equal(3); + }); }) - controller.signals.editorDragStopped(); - }); - it('editorDrag starts at pos 1 without grabbing caret and moves to 0', function(done) { - var controller = require('../controller')({ - //instantiate some default val's here: - state: { - selectionLayer: { - selected: false, - }, - caretPosition: 8, - sequenceData: { - sequence: 'atatatatat', - circular: true - }, - } - }); - controller.signals.editorDragStarted({nearestBP: 1, caretGrabbed: false}); - testSignal(controller.signals.editorDragged, { - nearestBP: 0, - }, function() { - controller.get('selectionLayer').start.should.equal(0); - controller.get('selectionLayer').end.should.equal(0); - controller.get('caretPosition').should.equal(0); - done() + .then(function () { + return testSignal(controller, controller.signals.editorDragged, {nearestBP: 1}, () => { + controller.get('selectionLayer').selected.should.equal(false); + controller.get('caretPosition').should.equal(1); + }); + }) + .then(function () { + return testSignal(controller, controller.signals.editorDragged, {nearestBP: 0}, () => { + controller.get('selectionLayer').start.should.equal(1); + controller.get('selectionLayer').end.should.equal(9); + controller.get('caretPosition').should.equal(10); + }); }) - controller.signals.editorDragStopped(); }); - it.only('editorDrag starts by grabbing caret at pos 1 and moves around the sequence', function(done) { - var controller = require('../controller')({ - //instantiate some default val's here: - state: { - selectionLayer: { - selected: false, - }, - caretPosition: 1, - sequenceData: { - sequence: 'atatatatat', - circular: true - }, - } - }); - controller.signals.editorDragStarted({nearestBP: 1, caretGrabbed: true}); - controller.signals.editorDragged({nearestBP: 0}); - debugger; - testSignal(controller.signals.editorDragged, { - nearestBP: 1, - }, function() { - controller.get('selectionLayer').start.should.equal(1); - controller.get('selectionLayer').end.should.equal(1); - controller.get('caretPosition').should.equal(0); - done() + it('editorDrag starts by grabbing caret at pos 1 and moves to 0, 1, 5', function() { + return testSignal(controller, controller.signals.editorDragStarted, {nearestBP: 1, caretGrabbed: true}) + .then(function () { + return testSignal(controller, controller.signals.editorDragged, {nearestBP: 0}, () => { + controller.get('selectionLayer').start.should.equal(0); + controller.get('selectionLayer').end.should.equal(0); + controller.get('caretPosition').should.equal(10); + }); + }) + .then(function () { + return testSignal(controller, controller.signals.editorDragged, {nearestBP: 1}, () => { + controller.get('selectionLayer').selected.should.equal(false); + controller.get('caretPosition').should.equal(1); + }); + }) + .then(function () { + return testSignal(controller, controller.signals.editorDragged, {nearestBP: 5}, () => { + controller.get('selectionLayer').start.should.equal(5); + controller.get('selectionLayer').end.should.equal(1); + controller.get('caretPosition').should.equal(5); + }); }) - controller.signals.editorDragStopped(); }); }); \ No newline at end of file diff --git a/app/cerebral/testSignal.js b/app/cerebral/testSignal.js index 19515b4c1..69b055994 100644 --- a/app/cerebral/testSignal.js +++ b/app/cerebral/testSignal.js @@ -1,7 +1,16 @@ -export default function testSignal (signal, data, test) { - signal.chain.push(function () { - signal.chain.pop(); - test(); - }) - signal(data); +// helper function to wrap a signal in a promise and optionally run a test when the signal is done +export default function testSignal(controller, signal, data, test) { + return new Promise(function (resolve, reject) { + controller.once('signalEnd', function () { + if (typeof test === 'function') { + // try { + test(); + // } catch (e) { + // return reject(e); + // } + } + resolve(); + }); + signal(data); + }); } \ No newline at end of file From e36131daebe9f6c34632bf0acc5fd08381f387a0 Mon Sep 17 00:00:00 2001 From: tnrich Date: Mon, 16 Nov 2015 23:31:48 -0800 Subject: [PATCH 07/15] tiny fix --- app/cerebral/signals/editorDragged.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/cerebral/signals/editorDragged.test.js b/app/cerebral/signals/editorDragged.test.js index ca4c80c52..00b2397ad 100644 --- a/app/cerebral/signals/editorDragged.test.js +++ b/app/cerebral/signals/editorDragged.test.js @@ -12,7 +12,7 @@ var controller = require('../controller')({ } }); -var testSignal = require('../testSignal2'); +var testSignal = require('../testSignal'); describe('editorDragged circular sequence', function() { beforeEach(function() { controller.reset(); From 6139bd3f1056231dd787341a913a96cd94ac14f2 Mon Sep 17 00:00:00 2001 From: tnrich Date: Tue, 17 Nov 2015 13:32:19 -0800 Subject: [PATCH 08/15] fixing circ view cursor grabbing --- app/CircularView.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/CircularView.js b/app/CircularView.js index 6c86b4c01..c28a5a762 100644 --- a/app/CircularView.js +++ b/app/CircularView.js @@ -63,7 +63,7 @@ class CircularView extends React.Component { var angle = Math.atan2(clickY, clickX) + Math.PI/2 if (angle < 0) angle += Math.PI * 2 console.log('angle: ' + JSON.stringify(angle,null,4)); - var caretGrabbed = event.target.className === "cursor" + var caretGrabbed = event.target.className && event.target.className.animVal === "cursor" var nearestBP = Math.floor(angle / Math.PI / 2 * sequenceLength) callback({ shiftHeld: event.shiftKey, @@ -266,7 +266,8 @@ function Caret ({caretPosition, sequenceLength, innerRadius, outerRadius}) { eAngle={ endAngle } height={ 0 }> Date: Wed, 18 Nov 2015 16:16:09 -0800 Subject: [PATCH 09/15] tweaking true/false triggers for readonly --- app/StatusBar.js | 10 +++++----- app/cerebral/actions/deleteSequence.js | 2 ++ app/cerebral/actions/setEditState.js | 8 +++----- app/cerebral/signals.js | 11 ++++++----- app/cerebral/state.js | 10 +++++----- 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/app/StatusBar.js b/app/StatusBar.js index a24765281..ed4dd2f0b 100644 --- a/app/StatusBar.js +++ b/app/StatusBar.js @@ -10,14 +10,14 @@ import styles from './status-bar.css'; selectedSeqMeltingTemp: ['selectedSeqMeltingTemp'], caretPosition: ['caretPosition'], selectionLayer: ['selectionLayer'], - readOnly: ['readOnly'] + // readOnly: ['readOnly'] }) @propTypes({ sequenceLength: PropTypes.number.isRequired, selectedSeqMeltingTemp: PropTypes.number.isRequired, caretPosition: PropTypes.number.isRequired, selectionLayer: PropTypes.object.isRequired, - readOnly: PropTypes.bool.isRequired + // readOnly: PropTypes.bool.isRequired }) export default class StatusBar extends React.Component { @@ -27,7 +27,7 @@ export default class StatusBar extends React.Component { selectedSeqMeltingTemp, caretPosition, selectionLayer, - readOnly, + // readOnly, signals } = this.props; @@ -39,9 +39,9 @@ export default class StatusBar extends React.Component {
+ signals.setEditState(true);}}>Set Edit True + signals.setEditState(false);}}>Set Edit False
Length
diff --git a/app/cerebral/actions/deleteSequence.js b/app/cerebral/actions/deleteSequence.js index c3172ca26..eff951112 100644 --- a/app/cerebral/actions/deleteSequence.js +++ b/app/cerebral/actions/deleteSequence.js @@ -6,6 +6,8 @@ var assign = require('lodash/object/assign'); export default function deleteSequence({selectionLayer, sequenceData}, tree, output) { ac.throw(ac.range, selectionLayer) var newCaretPosition = selectionLayer.start; + console.log("got into deleteSequence"); + console.log("selection: " + selectionLayer.start + " " + selectionLayer.end); if (selectionLayer.start > selectionLayer.end) { newCaretPosition = selectionLayer.start - selectionLayer.end - 1; } diff --git a/app/cerebral/actions/setEditState.js b/app/cerebral/actions/setEditState.js index e67b9e860..fd0ed5759 100644 --- a/app/cerebral/actions/setEditState.js +++ b/app/cerebral/actions/setEditState.js @@ -1,8 +1,6 @@ export default function setEditState(input, tree, output) { // - console.log("setting edit state to read only"); + console.log("setting edit state to " + input); + tree.set('readOnly', input); console.log("readOnly: " + tree.get('readOnly')); - tree.set('readOnly', true); -} - -// setEditState.outputs = ['shiftHeld', 'shiftNotHeld']; \ No newline at end of file +} \ No newline at end of file diff --git a/app/cerebral/signals.js b/app/cerebral/signals.js index 5b3115368..2594b7d63 100644 --- a/app/cerebral/signals.js +++ b/app/cerebral/signals.js @@ -86,11 +86,12 @@ export default function(controller, options) { jumpToRow: [a.jumpToRow], // sl: in progress setEditState: [a.setEditState], - testSignal: a.addEditModeOnly([ - function(input, tree, output) { - console.log("test signal"); - } - ]), + // testSignal: a.addEditModeOnly([ + // function(input, tree, output) { + // console.log("test signal"); + // } + // ]), + // sl: working on this one now backspacePressed: a.addEditModeOnly([ a.getData('selectionLayer', 'sequenceLength', 'sequenceData'), a.checkLayerIsSelected, { diff --git a/app/cerebral/state.js b/app/cerebral/state.js index 750ea7aed..ad4646ee2 100644 --- a/app/cerebral/state.js +++ b/app/cerebral/state.js @@ -47,9 +47,9 @@ module.exports = { width: 500 }, cutsiteLabelSelectionLayer: { - start: -1, - end: -1, - selected: false, + start: 0, + end: 0, + selected: true, cursorAtEnd: true }, editorDrag: { @@ -66,8 +66,8 @@ module.exports = { width: 500 }, selectionLayer: { - start: -1, - end: -1, + start: 0, + end: 0, selected: false, cursorAtEnd: true }, From 76b94d06ec227ede5548eb8a39843b0dd0138dc2 Mon Sep 17 00:00:00 2001 From: Sarah A LaFrance Date: Thu, 19 Nov 2015 14:27:18 -0800 Subject: [PATCH 10/15] setting up delete, not updating --- app/StatusBar.js | 4 ++-- app/cerebral/actions/deleteSequence.js | 2 +- app/cerebral/actions/setEditState.js | 9 +++++++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/StatusBar.js b/app/StatusBar.js index ed4dd2f0b..fee09f2a0 100644 --- a/app/StatusBar.js +++ b/app/StatusBar.js @@ -39,9 +39,9 @@ export default class StatusBar extends React.Component {
+ signals.setEditState(false);}}>Set Edit True + signals.setEditState(true);}}>Set Edit False
Length
diff --git a/app/cerebral/actions/deleteSequence.js b/app/cerebral/actions/deleteSequence.js index eff951112..f27e09e59 100644 --- a/app/cerebral/actions/deleteSequence.js +++ b/app/cerebral/actions/deleteSequence.js @@ -7,7 +7,6 @@ export default function deleteSequence({selectionLayer, sequenceData}, tree, out ac.throw(ac.range, selectionLayer) var newCaretPosition = selectionLayer.start; console.log("got into deleteSequence"); - console.log("selection: " + selectionLayer.start + " " + selectionLayer.end); if (selectionLayer.start > selectionLayer.end) { newCaretPosition = selectionLayer.start - selectionLayer.end - 1; } @@ -21,6 +20,7 @@ export default function deleteSequence({selectionLayer, sequenceData}, tree, out //regular deletion newSequenceData.sequence = sequenceData.sequence.slice(0, selectionLayer.start) + sequenceData.sequence.slice(selectionLayer.end + 1, sequenceData.sequence.length); } + // console.log("new sequence: " + newSequenceData.sequence); } //trim and remove features newSequenceData.features = applyDeleteToAnnotations(sequenceData.features); diff --git a/app/cerebral/actions/setEditState.js b/app/cerebral/actions/setEditState.js index fd0ed5759..6bb85d2c3 100644 --- a/app/cerebral/actions/setEditState.js +++ b/app/cerebral/actions/setEditState.js @@ -1,6 +1,11 @@ export default function setEditState(input, tree, output) { // - console.log("setting edit state to " + input); - tree.set('readOnly', input); + // console.log("setting read only to " + input); + // tree.set('readOnly', input); + if(input) { + tree.set('readOnly', true); + } else { + tree.set('readOnly', false); + } console.log("readOnly: " + tree.get('readOnly')); } \ No newline at end of file From 693fa7965302043ecbb0938234cfecd4a5bc21a1 Mon Sep 17 00:00:00 2001 From: Sarah A LaFrance Date: Thu, 19 Nov 2015 16:11:42 -0800 Subject: [PATCH 11/15] delete progress, removed readonly test code --- app/StatusBar.js | 13 ++++--------- app/cerebral/actions/deleteSequence.js | 4 +++- app/cerebral/actions/setEditState.js | 11 ----------- app/cerebral/signals.js | 9 +-------- 4 files changed, 8 insertions(+), 29 deletions(-) delete mode 100644 app/cerebral/actions/setEditState.js diff --git a/app/StatusBar.js b/app/StatusBar.js index fee09f2a0..b55047b47 100644 --- a/app/StatusBar.js +++ b/app/StatusBar.js @@ -10,14 +10,14 @@ import styles from './status-bar.css'; selectedSeqMeltingTemp: ['selectedSeqMeltingTemp'], caretPosition: ['caretPosition'], selectionLayer: ['selectionLayer'], - // readOnly: ['readOnly'] + readOnly: ['readOnly'] }) @propTypes({ sequenceLength: PropTypes.number.isRequired, selectedSeqMeltingTemp: PropTypes.number.isRequired, caretPosition: PropTypes.number.isRequired, selectionLayer: PropTypes.object.isRequired, - // readOnly: PropTypes.bool.isRequired + readOnly: PropTypes.bool.isRequired }) export default class StatusBar extends React.Component { @@ -27,7 +27,7 @@ export default class StatusBar extends React.Component { selectedSeqMeltingTemp, caretPosition, selectionLayer, - // readOnly, + readOnly, signals } = this.props; @@ -37,12 +37,7 @@ export default class StatusBar extends React.Component { return (
-
- - -
+
Read Only status: {readOnly.toString()}
Length
{sequenceLength}
diff --git a/app/cerebral/actions/deleteSequence.js b/app/cerebral/actions/deleteSequence.js index f27e09e59..9b9572bab 100644 --- a/app/cerebral/actions/deleteSequence.js +++ b/app/cerebral/actions/deleteSequence.js @@ -46,5 +46,7 @@ export default function deleteSequence({selectionLayer, sequenceData}, tree, out return []; } } - output({sequenceData: tidyUpSequenceData(newSequenceData, true), caretPosition: newCaretPosition}); + tree.set('sequenceData', tidyUpSequenceData(newSequenceData, true)); + tree.set('caretPosition', newCaretPosition); + // output({sequenceData: tidyUpSequenceData(newSequenceData, true), caretPosition: newCaretPosition}); } diff --git a/app/cerebral/actions/setEditState.js b/app/cerebral/actions/setEditState.js deleted file mode 100644 index 6bb85d2c3..000000000 --- a/app/cerebral/actions/setEditState.js +++ /dev/null @@ -1,11 +0,0 @@ -export default function setEditState(input, tree, output) { - // - // console.log("setting read only to " + input); - // tree.set('readOnly', input); - if(input) { - tree.set('readOnly', true); - } else { - tree.set('readOnly', false); - } - console.log("readOnly: " + tree.get('readOnly')); -} \ No newline at end of file diff --git a/app/cerebral/signals.js b/app/cerebral/signals.js index 2594b7d63..c11ccb30e 100644 --- a/app/cerebral/signals.js +++ b/app/cerebral/signals.js @@ -84,14 +84,7 @@ export default function(controller, options) { //lower priority addAnnotations: [a.addAnnotations], jumpToRow: [a.jumpToRow], - // sl: in progress - setEditState: [a.setEditState], - // testSignal: a.addEditModeOnly([ - // function(input, tree, output) { - // console.log("test signal"); - // } - // ]), - // sl: working on this one now + // sl: working on this one now, need to debus backspacePressed: a.addEditModeOnly([ a.getData('selectionLayer', 'sequenceLength', 'sequenceData'), a.checkLayerIsSelected, { From 6685622ea3292c514b735177ebc6add1ac05b489 Mon Sep 17 00:00:00 2001 From: Sarah A LaFrance Date: Fri, 20 Nov 2015 11:51:57 -0800 Subject: [PATCH 12/15] fixed weirdness with selection layer --- app/cerebral/actions/deleteSequence.js | 10 +++++----- app/cerebral/state.js | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/cerebral/actions/deleteSequence.js b/app/cerebral/actions/deleteSequence.js index 9b9572bab..7e0350fea 100644 --- a/app/cerebral/actions/deleteSequence.js +++ b/app/cerebral/actions/deleteSequence.js @@ -2,15 +2,16 @@ var ac = require('ve-api-check'); var adjustRangeToDeletionOfAnotherRange = require('ve-range-utils/adjustRangeToDeletionOfAnotherRange'); var tidyUpSequenceData = require('ve-sequence-utils/tidyUpSequenceData'); var assign = require('lodash/object/assign'); +var setSelectionLayer = require('./setSelectionLayer'); export default function deleteSequence({selectionLayer, sequenceData}, tree, output) { ac.throw(ac.range, selectionLayer) var newCaretPosition = selectionLayer.start; - console.log("got into deleteSequence"); if (selectionLayer.start > selectionLayer.end) { newCaretPosition = selectionLayer.start - selectionLayer.end - 1; } - var newSequenceData = {}; + // lodash assign + var newSequenceData =assign({}, sequenceData); if (sequenceData.sequence) { //splice the underlying sequence if (selectionLayer.start > selectionLayer.end) { @@ -20,7 +21,6 @@ export default function deleteSequence({selectionLayer, sequenceData}, tree, out //regular deletion newSequenceData.sequence = sequenceData.sequence.slice(0, selectionLayer.start) + sequenceData.sequence.slice(selectionLayer.end + 1, sequenceData.sequence.length); } - // console.log("new sequence: " + newSequenceData.sequence); } //trim and remove features newSequenceData.features = applyDeleteToAnnotations(sequenceData.features); @@ -48,5 +48,5 @@ export default function deleteSequence({selectionLayer, sequenceData}, tree, out } tree.set('sequenceData', tidyUpSequenceData(newSequenceData, true)); tree.set('caretPosition', newCaretPosition); - // output({sequenceData: tidyUpSequenceData(newSequenceData, true), caretPosition: newCaretPosition}); -} + setSelectionLayer(false, tree); +} \ No newline at end of file diff --git a/app/cerebral/state.js b/app/cerebral/state.js index ad4646ee2..750ea7aed 100644 --- a/app/cerebral/state.js +++ b/app/cerebral/state.js @@ -47,9 +47,9 @@ module.exports = { width: 500 }, cutsiteLabelSelectionLayer: { - start: 0, - end: 0, - selected: true, + start: -1, + end: -1, + selected: false, cursorAtEnd: true }, editorDrag: { @@ -66,8 +66,8 @@ module.exports = { width: 500 }, selectionLayer: { - start: 0, - end: 0, + start: -1, + end: -1, selected: false, cursorAtEnd: true }, From ee7d945a10b76e1cc0ce1bfe6a300769f161a6fd Mon Sep 17 00:00:00 2001 From: Sarah A LaFrance Date: Fri, 20 Nov 2015 15:17:07 -0800 Subject: [PATCH 13/15] backspace working for most cases now --- app/StatusBar.js | 3 ++- app/cerebral/actions/deleteSequence.js | 3 ++- app/cerebral/actions/prepDeleteOneBack.js | 22 +++++++--------------- app/cerebral/signals.js | 2 +- app/cerebral/state.js | 1 + 5 files changed, 13 insertions(+), 18 deletions(-) diff --git a/app/StatusBar.js b/app/StatusBar.js index b55047b47..0b12f7bbc 100644 --- a/app/StatusBar.js +++ b/app/StatusBar.js @@ -37,7 +37,8 @@ export default class StatusBar extends React.Component { return (
-
Read Only status: {readOnly.toString()}
+ + {readOnly ?
Read Only Mode
:
Editing Allowed
}
Length
{sequenceLength}
diff --git a/app/cerebral/actions/deleteSequence.js b/app/cerebral/actions/deleteSequence.js index 7e0350fea..d52bbfd3e 100644 --- a/app/cerebral/actions/deleteSequence.js +++ b/app/cerebral/actions/deleteSequence.js @@ -4,7 +4,8 @@ var tidyUpSequenceData = require('ve-sequence-utils/tidyUpSequenceData'); var assign = require('lodash/object/assign'); var setSelectionLayer = require('./setSelectionLayer'); -export default function deleteSequence({selectionLayer, sequenceData}, tree, output) { +export default function deleteSequence(input, tree) { + var {selectionLayer, sequenceData} = tree.get(); ac.throw(ac.range, selectionLayer) var newCaretPosition = selectionLayer.start; if (selectionLayer.start > selectionLayer.end) { diff --git a/app/cerebral/actions/prepDeleteOneBack.js b/app/cerebral/actions/prepDeleteOneBack.js index c005d11fa..d7d8e3d73 100644 --- a/app/cerebral/actions/prepDeleteOneBack.js +++ b/app/cerebral/actions/prepDeleteOneBack.js @@ -1,16 +1,8 @@ -export default function prepSelectionLayer (numberToMove, cursorAtEnd) { - return function prepSelectionLayer({caretPosition, selectionLayer}, tree, output) { - if (caretPosition > 0) { - output({ - selectionLayer: { - start: caretPosition - 1, - end: caretPosition - 1, - cursorAtEnd: cursorAtEnd, - } - }); - } else { - throw new Error('no caret or selection layer to delete!'); - } - } -} +var normalizePositionByRangeLength = require('ve-range-utils/normalizePositionByRangeLength'); +var setSelectionLayer = require('./setSelectionLayer'); +export default function prepSelectionLayer(input, tree, output) { + var {caretPosition, sequenceLength} = tree.get(); + var normedCaretPosition = normalizePositionByRangeLength(caretPosition -1, sequenceLength, true) + setSelectionLayer({selectionLayer: {'start': normedCaretPosition, 'end': normedCaretPosition}}, tree); +} \ No newline at end of file diff --git a/app/cerebral/signals.js b/app/cerebral/signals.js index c11ccb30e..98f70071c 100644 --- a/app/cerebral/signals.js +++ b/app/cerebral/signals.js @@ -89,7 +89,7 @@ export default function(controller, options) { a.getData('selectionLayer', 'sequenceLength', 'sequenceData'), a.checkLayerIsSelected, { selected: [a.deleteSequence], - notSelected: [a.getData('caretPosition'), a.prepDeleteOneBack, a.deleteSequence] + notSelected: [a.prepDeleteOneBack, a.deleteSequence] } ]), sequenceDataInserted: a.addEditModeOnly([ diff --git a/app/cerebral/state.js b/app/cerebral/state.js index 750ea7aed..bfdbb61de 100644 --- a/app/cerebral/state.js +++ b/app/cerebral/state.js @@ -76,6 +76,7 @@ module.exports = { features: [], translations: [], parts: [], + circular: false }, userEnzymeList: [ 'rsplkii', From 4b00362c96b491db0d0941ad8672a2f0925d0c13 Mon Sep 17 00:00:00 2001 From: Sarah A LaFrance Date: Mon, 30 Nov 2015 13:25:46 -0800 Subject: [PATCH 14/15] trying to fix tests --- app/cerebral/actions/deleteSequence.js | 5 +++-- app/cerebral/actions/prepDeleteOneBack.js | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/cerebral/actions/deleteSequence.js b/app/cerebral/actions/deleteSequence.js index d52bbfd3e..f31d773b4 100644 --- a/app/cerebral/actions/deleteSequence.js +++ b/app/cerebral/actions/deleteSequence.js @@ -4,10 +4,11 @@ var tidyUpSequenceData = require('ve-sequence-utils/tidyUpSequenceData'); var assign = require('lodash/object/assign'); var setSelectionLayer = require('./setSelectionLayer'); -export default function deleteSequence(input, tree) { - var {selectionLayer, sequenceData} = tree.get(); +export default function deleteSequence({selectionLayer, sequenceData}, tree, output) { + // var {selectionLayer, sequenceData, } = tree.get(); ac.throw(ac.range, selectionLayer) var newCaretPosition = selectionLayer.start; + if (selectionLayer.start > selectionLayer.end) { newCaretPosition = selectionLayer.start - selectionLayer.end - 1; } diff --git a/app/cerebral/actions/prepDeleteOneBack.js b/app/cerebral/actions/prepDeleteOneBack.js index d7d8e3d73..2f51d9789 100644 --- a/app/cerebral/actions/prepDeleteOneBack.js +++ b/app/cerebral/actions/prepDeleteOneBack.js @@ -3,6 +3,7 @@ var setSelectionLayer = require('./setSelectionLayer'); export default function prepSelectionLayer(input, tree, output) { var {caretPosition, sequenceLength} = tree.get(); - var normedCaretPosition = normalizePositionByRangeLength(caretPosition -1, sequenceLength, true) + var normedCaretPosition = normalizePositionByRangeLength(caretPosition -1, sequenceLength, true); + setSelectionLayer({selectionLayer: {'start': normedCaretPosition, 'end': normedCaretPosition}}, tree); } \ No newline at end of file From eb65fdd8e712381e1d87d08d4116b2324337c5d8 Mon Sep 17 00:00:00 2001 From: Sarah A LaFrance Date: Mon, 30 Nov 2015 13:42:40 -0800 Subject: [PATCH 15/15] Travis works now! delete is all set :) --- app/cerebral/actions/deleteSequence.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/cerebral/actions/deleteSequence.js b/app/cerebral/actions/deleteSequence.js index f31d773b4..a7b987bb0 100644 --- a/app/cerebral/actions/deleteSequence.js +++ b/app/cerebral/actions/deleteSequence.js @@ -2,7 +2,7 @@ var ac = require('ve-api-check'); var adjustRangeToDeletionOfAnotherRange = require('ve-range-utils/adjustRangeToDeletionOfAnotherRange'); var tidyUpSequenceData = require('ve-sequence-utils/tidyUpSequenceData'); var assign = require('lodash/object/assign'); -var setSelectionLayer = require('./setSelectionLayer'); +// var setSelectionLayer = require('./setSelectionLayer'); export default function deleteSequence({selectionLayer, sequenceData}, tree, output) { // var {selectionLayer, sequenceData, } = tree.get(); @@ -48,7 +48,8 @@ export default function deleteSequence({selectionLayer, sequenceData}, tree, out return []; } } - tree.set('sequenceData', tidyUpSequenceData(newSequenceData, true)); - tree.set('caretPosition', newCaretPosition); - setSelectionLayer(false, tree); + // tree.set('sequenceData', tidyUpSequenceData(newSequenceData, true)); + // tree.set('caretPosition', newCaretPosition); + output({sequenceData: tidyUpSequenceData(newSequenceData, true), caretPosition: newCaretPosition}); + // setSelectionLayer(false, tree); } \ No newline at end of file