joseramonc / multi-cursor

:tada:
MIT License
44 stars 7 forks source link

adding new cursor after cursor movement #5

Closed jacekkopecky closed 9 years ago

jacekkopecky commented 9 years ago

When I add a few cursors, I can then move them around with normal cursor movement. However, a new cmd-alt-shift-down will add a new cursor below where the last cursor was added, not below where the last cursor is now. I think the new cursor should be added below the current position of the last cursor.

Here's how I currently do it:

atom.commands.add "atom-text-editor", "mine:add-cursor-down", ->
  addCursorInDirection(1)

atom.commands.add "atom-text-editor", "mine:add-cursor-up", ->
  addCursorInDirection(-1)

addCursorInDirection = (dir) ->
  editor = atom.workspace.getActiveTextEditor()
  cursor = editor.getLastCursor()
  coords = cursor.getBufferPosition()

  newcoords = { column: cursor.goalColumn || coords.column, row: coords.row + dir }
  newcursor = editor.addCursorAtBufferPosition(newcoords)

  newcursor.goalColumn = cursor.goalColumn || coords.column

However you'll note that this doesn't handle removing of cursors (which I can do with #4). But I suspect that would be easy by moving the last cursor to the buffer position of the second-to-last cursor - the editor will then merge it away.

jacekkopecky commented 9 years ago

Again, I'll be happy to do a PR if you like this.

joseramonc commented 9 years ago

@jacekkopecky Thank you, this is an issue I haven't been able to fix and I'd be very happy to merge a solution for this problem, you may send the same pull request for both issues if you like. Thanks for your help