fixed keyboard issue with default behaviour, still fighting a bug in binSearch that makes it loop forever...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2013-05-07 02:16:57 +04:00
parent f619e62658
commit 53f06951f7
3 changed files with 20 additions and 5 deletions

View File

@ -160,6 +160,7 @@ function getImageBefore(image, ribbon, mode){
//
// NOTE: this is here mostly to make debuging easy...
function isBetween(a, i, lst){
console.log('>>>', a, i, lst)
var b = lst[i]
var c = lst[i+1]
// hit...
@ -182,6 +183,7 @@ function isBetween(a, i, lst){
// NOTE: by default this will use isBetween as a predicate.
// NOTE: this still depends on .indexOf(...), to disable set
// disable_direct_indexing to true
// XXX BUG this tends to fall into infinite loops...
function binSearch(target, lst, check, return_position, disable_direct_indexing){
// XXX is this the correct default?
check = check == null ? isBetween : check
@ -195,13 +197,16 @@ function binSearch(target, lst, check, return_position, disable_direct_indexing)
return lst[lst.length-1]
}
// special case: head...
if(check(target, 0, lst) == 0){
var res = check(target, 0, lst)
if(res == 0){
return lst[0]
} else if(res < 0){
// no hit...
return return_position ? -1 : null
}
var l = Math.ceil(lst.length/2)
var i = l
var res
while(l > 0){
l = Math.ceil(l/2)

View File

@ -234,6 +234,7 @@ $(function(){
//var rr = r.clone()
//var rrr = r.clone()
// XXX use something like loadImages()...
$('.ribbon-set')
.append(r)
//.append(rr)
@ -250,8 +251,11 @@ $(function(){
function(k){console.log(k)}))
// dynamic loading...
if(true){
DYNAMIC_LOADING = true
if(DYNAMIC_LOADING){
// XXX move to a setup function in the lib...
// XXX update this depending on zoom and navigation speed...
var LOADER_THRESHOLD = 2

View File

@ -76,42 +76,48 @@ var KEYBOARD_CONFIG = {
},
*/
Home: function(){
event.preventDefault()
firstImage()
centerRibbons()
return false
},
End: function(){
event.preventDefault()
lastImage()
centerRibbons()
return false
},
// combined navigation and editor actions...
Up: {
default: function(){
event.preventDefault()
prevRibbon(DIRECTION)
centerRibbons()
},
shift: function(){
event.preventDefault()
shiftImageUp(null, DIRECTION)
centerRibbons()
},
'ctrl+shift': function(){
event.preventDefault()
shiftImageUpNewRibbon(null, DIRECTION)
centerRibbons()
},
},
Down: {
default: function(){
event.preventDefault()
nextRibbon(DIRECTION)
centerRibbons()
},
shift: function(){
event.preventDefault()
shiftImageDown(null, DIRECTION)
centerRibbons()
},
'ctrl+shift': function(){
event.preventDefault()
shiftImageDownNewRibbon(null, DIRECTION)
centerRibbons()
},