openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

scroll_test.min.js (4770B)


      1 (function() {
      2   "use strict";
      3 
      4   namespace = "scroll_";
      5 
      6   testCM("bars_hidden", function(cm) {
      7     for (var i = 0;; i++) {
      8       var wrapBox = cm.getWrapperElement().getBoundingClientRect();
      9       var scrollBox = cm.getScrollerElement().getBoundingClientRect();
     10       is(wrapBox.bottom < scrollBox.bottom - 10);
     11       is(wrapBox.right < scrollBox.right - 10);
     12       if (i == 1) break;
     13       cm.getWrapperElement().style.height = "auto";
     14       cm.refresh();
     15     }
     16   });
     17   
     18   function barH(cm) { return byClassName(cm.getWrapperElement(), "CodeMirror-hscrollbar")[0]; }
     19   function barV(cm) { return byClassName(cm.getWrapperElement(), "CodeMirror-vscrollbar")[0]; }
     20 
     21   function displayBottom(cm, scrollbar) {
     22     if (scrollbar && cm.display.scroller.offsetHeight > cm.display.scroller.clientHeight)
     23       return barH(cm).getBoundingClientRect().top;
     24     else
     25       return cm.getWrapperElement().getBoundingClientRect().bottom - 1;
     26   }
     27 
     28   function displayRight(cm, scrollbar) {
     29     if (scrollbar && cm.display.scroller.offsetWidth > cm.display.scroller.clientWidth)
     30       return barV(cm).getBoundingClientRect().left;
     31     else
     32       return cm.getWrapperElement().getBoundingClientRect().right - 1;
     33   }
     34 
     35   function testMovedownFixed(cm, hScroll) {
     36     cm.setSize("100px", "100px");
     37     if (hScroll) cm.setValue(new Array(100).join("x"));
     38     var bottom = displayBottom(cm, hScroll);
     39     for (var i = 0; i < 30; i++) {
     40       cm.replaceSelection("x\n");
     41       var cursorBottom = cm.cursorCoords(null, "window").bottom;
     42       is(cursorBottom <= bottom);
     43     }
     44     is(cursorBottom >= bottom - 5);
     45   }
     46 
     47   testCM("movedown_fixed", function(cm) {testMovedownFixed(cm, false);});
     48   testCM("movedown_hscroll_fixed", function(cm) {testMovedownFixed(cm, true);});
     49 
     50   function testMovedownResize(cm, hScroll) {
     51     cm.getWrapperElement().style.height = "auto";
     52     if (hScroll) cm.setValue(new Array(100).join("x"));
     53     cm.refresh();
     54     for (var i = 0; i < 30; i++) {
     55       cm.replaceSelection("x\n");
     56       var bottom = displayBottom(cm, hScroll);
     57       var cursorBottom = cm.cursorCoords(null, "window").bottom;
     58       is(cursorBottom <= bottom);
     59       is(cursorBottom >= bottom - 5);
     60     }
     61   }
     62 
     63   testCM("movedown_resize", function(cm) {testMovedownResize(cm, false);});
     64   testCM("movedown_hscroll_resize", function(cm) {testMovedownResize(cm, true);});
     65 
     66   function testMoveright(cm, wrap, scroll) {
     67     cm.setSize("100px", "100px");
     68     if (wrap) cm.setOption("lineWrapping", true);
     69     if (scroll) {
     70       cm.setValue("\n" + new Array(100).join("x\n"));
     71       cm.setCursor(Pos(0, 0));
     72     }
     73     var right = displayRight(cm, scroll);
     74     for (var i = 0; i < 10; i++) {
     75       cm.replaceSelection("xxxxxxxxxx");
     76       var cursorRight = cm.cursorCoords(null, "window").right;
     77       is(cursorRight < right);
     78     }
     79     if (!wrap) is(cursorRight > right - 20);
     80   }
     81 
     82   testCM("moveright", function(cm) {testMoveright(cm, false, false);});
     83   testCM("moveright_wrap", function(cm) {testMoveright(cm, true, false);});
     84   testCM("moveright_scroll", function(cm) {testMoveright(cm, false, true);});
     85   testCM("moveright_scroll_wrap", function(cm) {testMoveright(cm, true, true);});
     86 
     87   testCM("suddenly_wide", function(cm) {
     88     addDoc(cm, 100, 100);
     89     cm.replaceSelection(new Array(600).join("l ") + "\n");
     90     cm.execCommand("goLineUp");
     91     cm.execCommand("goLineEnd");
     92     is(barH(cm).scrollLeft > cm.getScrollerElement().scrollLeft - 1);
     93   });
     94 
     95   testCM("wrap_changes_height", function(cm) {
     96     var line = new Array(20).join("a ") + "\n";
     97     cm.setValue(new Array(20).join(line));
     98     var box = cm.getWrapperElement().getBoundingClientRect();
     99     cm.setSize(cm.cursorCoords(Pos(0), "window").right - box.left + 2,
    100                cm.cursorCoords(Pos(19, 0), "window").bottom - box.top + 2);
    101     cm.setCursor(Pos(19, 0));
    102     cm.replaceSelection("\n");
    103     is(cm.cursorCoords(null, "window").bottom < displayBottom(cm, false));
    104   }, {lineWrapping: true});
    105 
    106   testCM("height_auto_with_gutter_expect_no_scroll_after_line_delete", function(cm) {
    107     cm.setSize(null, "auto");
    108     cm.setValue("x\n");
    109     cm.execCommand("goDocEnd");
    110     cm.execCommand("delCharBefore");
    111     eq(cm.getScrollInfo().top, 0);
    112     cm.scrollTo(null, 10);
    113     is(cm.getScrollInfo().top < 5);
    114   }, {lineNumbers: true});
    115 
    116   testCM("bidi_ensureCursorVisible", function(cm) {
    117     cm.setValue("<dd>وضع الاستخدام. عندما لا تعطى، وهذا الافتراضي إلى الطريقة الاولى\n");
    118     cm.execCommand("goLineStart");
    119     eq(cm.getScrollInfo().left, 0);
    120     cm.execCommand("goCharRight");
    121     cm.execCommand("goCharRight");
    122     cm.execCommand("goCharRight");
    123     eqCursorPos(cm.getCursor(), Pos(0, 3, "before"));
    124     eq(cm.getScrollInfo().left, 0);
    125   }, {lineWrapping: false});
    126 })();