How to scroll inactive editor?


#1

How to make inactive editor scroll to desire position?
I have editor in inactive pane and I’m trying to scroll it with this:

inactiveEditor.scrollToBufferPosition( position );

tried also

inactiveEditor.setCursorBufferPosition( [row, col], { autoscroll: true } );

but with no success, scroll isn’t affected until i click on editor or focus pane.
Is it a bug or am I doing something wrong?
I’m using Atom 1.19.0


#2

It might help if you shared the whole function.


#3

here relevant code:
this.editor is editor inside active pane
this.previewEditor is editor inside inactive pane

  PreviewView.prototype.syncScroll = function(){
    var bufferPosition, bufferRow, previewRow;
    if (!atom.config.get('ehelon-source-preview.enableSyncScroll')) {
      return;
    }
    bufferPosition = this.editor.getCursorBufferPosition();
    bufferRow = bufferPosition.row;
    /* mapping from editor coordinates to previewEditor coordinates */
    previewRow = this.getPreviewLinePosition(bufferPosition);
    if (previewRow == null) {
      return;
    }
    /* moving cursor to mapped location - cursor moved, but no scrolling */
    this.previewEditor.setCursorBufferPosition([previewRow, 0], {
      autoscroll: true
    });
    this.previewEditor.scrollToBufferPosition([previewRow, 0]);
    /* selecting mapped line - works as expected */
    this.previewEditor.clearSelections();
    this.previewEditor.selectLinesContainingCursors();
  };

#4

If setCursorBufferPosition works, then I can’t think of any reason why scrollToBufferPosition would not. That’s mysterious.


#5

After some research i looks that in stable 1.18 release everything works as expected.
I determined that minimal code that cause problem for me goes like this:

  • I create a new editor
  • split active pane with this new editor as only item
  • focus to new pane.

I don’t even invoke any scrolling function. It looks like this:

this is function that i invoke with a command:

toggle: function(){
    var editor, inactiveEditor, activePane, newPane;
    editor = atom.workspace.getActiveTextEditor();
    if (!editor) {
      return;
    }
    inactiveEditor = atom.workspace.buildTextEditor();
    inactiveEditor.getTitle = function(){
      return 'Source Preview';
    };
    inactiveEditor.setGrammar(atom.grammars.grammarForScopeName('source.js'));
    inactiveEditor.isModified = function(){
      return false;
    };
    inactiveEditor.setText(editor.getText());
    activePane = atom.workspace.getActivePane();
    newPane = activePane.splitRight({
      items: [inactiveEditor]
    });
    activePane.activate();
  }

Is this a bug or am I doing something wrong?