Forcing viewport to full document size

cm.getViewport() returns {from: 0, to: 40}, but I’m unable to find a corresponding setter.

The issue is that users sometimes use the browser’s search function to find text, and if that text is outside of the current viewport it is not present in the DOM and is thus not found. What I’d like to do is add an event handler to Ctrl-F that quickly sets the viewport to its maximum extents, then allows the browser’s search to proceed as expected.

The only way to force the viewport to be bigger is to manipulate the viewportMargin option.

Oh, that’s perfect. Works like a charm:

function keyDown(e) {
  if ((e.key === 'f' || e.key === 'g') && (e.metaKey || e.ctrlKey)) {
    cm.setOption('viewportMargin', Infinity);
  }
}
document.addEventListener('keydown', keyDown);

When the user presses Ctrl-F, the editor instantly renders all lines, and the subsequent search work perfectly across the entire document. Likewise for Ctrl-G (repeat search). And Mac support.

Thanks!

You should keep in mind that this’ll ruin performance for very big documents, though.

@NeilFraser you might also want to look at this: Measure performance and modify viewportMargin accordingly