How to split active editor to two sessions?


#1

Hello.

Is there a way to split an active editor session to two pane sessions? The catch is that the two panes should remain in sync with each other.

One such example from another editor:
2018-07-04_18-28-45

In Atom it is possible for me to replicate an already saved file; the file is shown in two individual panes. Regrettably the two panes are not kept in sync. Changes needs to be saved to the file of one session before it reflects in the twin session

Thanks in advance for your attention.


#2

Take a look at the code of my edit-in-new-tab package (see it in action), it’s basically doing the same thing. It also works on unsaved files and without selections.


#3

Thank you for sharing your package with me.

I use the working shown in the above animated GIF as reference.
Please could you tell me:

  • Is it possible to edit on the “left” and on the “right” and have both keep in sync with each other?

  • Is it possible to duplicate the whole session?

Thank you for your time.
Regards.


#4

I think a look at the video answers the question

You mean without selection? Yes!


#5

Aren’t they? When I open a file (new or already saved), split it, and start typing, the changes appear in both panes. It looks exactly like your example gif, both in v1.28.0, and 1.29.0-beta0 (safe mode).


#6

I didn’t know about this, but it works the same for me.


#7

@Aerijo - thank you for your reply. You saved me some headache.

Just yesterday, I was demonstrating to my partner about this functionality not working in Atom. It must have been a temporary issue - today it is working as expected?!
2018-07-05_08-09-13

I will have to keep an eye on this one.
Perhaps it “malfunction” has something to do with some customization I did. :stuck_out_tongue:
Best to try it in safe mode next time. :blush:

Thank you @Aerijo and @idleberg for your time.


#8

@idleberg: Hello.

Sorry for my scheticism. I tried out edit-in-new-tab in August(?) 2017. I had some trouble with it then. I observed you made some additions since then.

The edit-in-new-tab package (or alike) will fit well in my work flow. I plan on re-evaluate edit-in-new-tab as soon as I am in range of a stronger/faster internet connection.

Best wishes.


#9

Hello @idleberg.

I have re-evaluated the edit-in-new-tab package. I very much like the way the code is isolated and pushed to the left margin. It is however very important to not touch the original code when the mirror came from.

No. The synchronization is only in one direction.

Yes it is possible if the whole text session is highlighted before triggering the edit-in-new-tab. The pit-fall is that only the mirrored side may be edited.


The take-away is that the package is good for mirroring a piece of code for the purpose of editing that piece. The selected code piece in the original source should not be deselected while working on the mirrored code.

@idleberg - thank you for the suggestion. This however do not fit the chaotic way that I code.

Best wishes.


#10

@idleberg - May I ask you to look at a possible design idea.

####     init.coffee    ####

# ****************************************************
#  SPLIT ACTIVE EDITOR TO NEW PANE
# ****************************************************
atom.commands.add 'atom-text-editor', 'custom:split-editor', (e) ->
  return false unless _ed1 = atom.workspace.getActiveTextEditor()
  return false unless _pane = atom.workspace.getActivePane()

  if _ed1.getSelectedText().length < 1
    # split editor pane as-is
    _pane.splitRight({copyActiveItem: true})
  else
    _selected = _ed1.getSelectedBufferRanges()[0]
    _ed1.setCursorBufferPosition(_selected.start)
    _pane.splitRight({copyActiveItem: true})
    # does Atom allow enough time to open 2nd pane?
    _ed2 = atom.workspace.getActiveTextEditor()
    if _selected.start.row > 0
      _ed2.setSelectedBufferRange([[0,0],[(_selected.start.row - 1),1000]])
      _ed2.foldSelectedLines()
    if _selected.end.row < _ed2.getLastBufferRow()
      _ed2.setSelectedBufferRange([[(_selected.end.row + 1),-1],[_ed2.getLastBufferRow(),-1]])
      _ed2.foldSelectedLines()
    _ed2.setCursorBufferPosition([_selected.start.row,0])

I hope you like it enough to use it - thank you.
BR