c-smile / sciter-sdk

Sciter is an embeddable HTML/CSS/scripting engine
http://sciter.com
Other
2.11k stars 223 forks source link

Incorrect code in Examples of dragndrop-manager. #131

Closed ValentiWorkLearning closed 5 years ago

ValentiWorkLearning commented 5 years ago

Function doScroll in ddm2 consist such code for scrolling a target container.

function doScroll(direction, distance) {
    if( !def.autoScroll ) return;
    var x = dd_container.scroll(#left);
    var y = dd_container.scroll(#top);
    switch(direction) {
      case 8: dd_container.scrollTo(x, y - distance * AUTO_SCROLL_DELTA); break; // top
      case 2: dd_container.scrollTo(x, y + distance * AUTO_SCROLL_DELTA); break; // bottom
      case 4: dd_container.scrollTo(x - distance * AUTO_SCROLL_DELTA, y); break; // left
      case 2: dd_container.scrollTo(x + distance * AUTO_SCROLL_DELTA, y); break; // right
    }
    return true;
  }

But calls of this function seems like:

          if( yv < y1 )      dd_container.sendEvent("drag-n-drop-ping", 8) || doScroll(8, y1 - yv); // generate "ping" event in case of UI need to scroll, etc.
          else if( yv > y2 ) dd_container.sendEvent("drag-n-drop-ping", 2) || doScroll(2, yv - y2); // evt.data -> direction
          else if( xv < x1 ) dd_container.sendEvent("drag-n-drop-ping", 4) || doScroll(4, x1 - xv); 
          else if( xv > x2 ) dd_container.sendEvent("drag-n-drop-ping", 6) || doScroll(6, xv > x2); 

So, look on the doScroll with first argument 6. In switch statement this value doesn't handled and right scroll doesn't occured. Probably there is a copy-pase error inside doScroll function and correct code is:

  function doScroll(direction, distance) {
    if( !def.autoScroll ) return;
    var x = dd_container.scroll(#left);
    var y = dd_container.scroll(#top);
    switch(direction) {
      case 8: dd_container.scrollTo(x, y - distance * AUTO_SCROLL_DELTA); break; // top
      case 2: dd_container.scrollTo(x, y + distance * AUTO_SCROLL_DELTA); break; // bottom
      case 4: dd_container.scrollTo(x - distance * AUTO_SCROLL_DELTA, y); break; // left
      case 6: dd_container.scrollTo(x + distance * AUTO_SCROLL_DELTA, y); break; // right
    }
    return true;
  }
c-smile commented 5 years ago

Thanks, fixed by https://github.com/c-smile/sciter-sdk/commit/b4c89b67f0d9632f53f5ac27e775db9830a3215f