fixed a couple of bug in .alignToRibbon(..), now seems to be working fine... still needs more testing.

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2016-08-07 02:35:20 +03:00
parent b47eecec3c
commit 4842da32fd
2 changed files with 35 additions and 7 deletions

View File

@ -587,7 +587,10 @@ actions.Actions({
// complex operations... // complex operations...
// XXX align to ribbon... // XXX need interactive mode for this...
// - on init: select start/end/base
// - allow user to reset/move
// - on accept: run
alignToRibbon: ['Ribbons|Edit/Align top ribbon to base', alignToRibbon: ['Ribbons|Edit/Align top ribbon to base',
function(target, start, end){ function(target, start, end){
this.data = this.data.alignToRibbon(target, start, end) this.data = this.data.alignToRibbon(target, start, end)

View File

@ -2216,28 +2216,53 @@ var DataPrototype = {
var above = this.getRibbon(r-1) var above = this.getRibbon(r-1)
} }
var that = this
// get the edge (left/right-most image) of the set of ribbons
// above the above ribbon calculated above... (no pun intended)
var _getEdge = function(side){
return Math[side == 'left' ? 'min' : 'max'].apply(null,
that.ribbon_order
.map(function(ribbon, i){
return i > r-1
? null
: that.getImageOrder(
side == 'left' ? 'first' : 'last',
ribbon) })
// cleanup...
.filter(function(i){
return i != null }))
}
start = start == null start = start == null
? this.getImageOrder('first', above) //? this.getImageOrder('first', above)
? _getEdge('left')
: this.getImageOrder(start) : this.getImageOrder(start)
end = end == null end = end == null
// NOTE: we need to exclude the last image in ribbon from // NOTE: we need to exclude the last image in ribbon from
// the next section, this the offset. // the next section, this the offset.
? this.getImageOrder('last', above)+1 //? this.getImageOrder('last', above)+1
? _getEdge('right')+1
: this.getImageOrder(end) : this.getImageOrder(end)
// split the data into three sections... // split the data into three sections...
var res = this.split(start, end) var res = this.split(start, end)
var rest = res.slice(1)
// cleanup... // cleanup...
// XXX do we actually need this??? // XXX do we actually need this???
res.forEach(function(e){ e.clear('empty') }) res.forEach(function(e){ return e.clear('empty') })
// set the base ribbon on the middle section... // set the base ribbon on the middle section...
rest[0].setBase(0) res[1].setBase(0)
// remove empty sections...
res = res.filter(function(e){ return e.length > 0 })
// join the resulting data to the base ribbon... // join the resulting data to the base ribbon...
res = res[0].join(rest) // NOTE: if we have only one non-empty section then nothing needs
// to be done...
if(res.length > 1){
res = res[0].join(res.slice(1))
}
// transfer data to new data object... // transfer data to new data object...
res.current = this.current res.current = this.current