code: function onViewportChange(cm) {
          var state = cm.state.foldGutter;
          window.clearTimeout(state.changeUpdate);
          state.changeUpdate = window.setTimeout(function () {
              var vp = cm.getViewport();
              if (state.from === state.to || vp.from - state.to > 20 || state.from - vp.to > 20) {
                  updateInViewport(cm);
              } else {
                  cm.operation(function () {
                      if (vp.from < state.from) {
                          updateFoldInfo(cm, vp.from, state.from);
                          state.from = vp.from;
                      }
                      if (vp.to > state.to) {
                          updateFoldInfo(cm, state.to, vp.to);
                          state.to = vp.to;
                      } else {
                          updateFoldInfo(cm, vp.from, vp.to);
                          state.to = vp.to;
                          state.from = vp.from;
                      }
                  });
              }
          }, 400);
      }
docs: Triggered on viewport changes e.g., user scrolls or resizes the viewport.
  @param {!CodeMirror} cm the CodeMirror instance for the active editor