2 _ = require 'underscore-plus'
3 {Point, Range} = require 'atom'
4 {Emitter, Disposable, CompositeDisposable} = require 'event-kit'
5 settings = require './settings'
7 Operators = require './operators/index'
8 Prefixes = require './prefixes'
9 Motions = require './motions/index'
10 InsertMode = require './insert-mode'
12 TextObjects = require './text-objects'
13 Utils = require './utils'
14 Scroll = require './scroll'
23 replaceModeListener: null
25 constructor: (@editorElement, @statusBarManager, @globalVimState) ->
26 @emitter = new Emitter
27 @subscriptions = new CompositeDisposable
28 @editor = @editorElement.getModel()
32 @subscriptions.add @editor.onDidDestroy => @destroy()
34 @editorElement.addEventListener 'mouseup', @checkSelections
35 if atom.commands.onDidDispatch?
36 @subscriptions.add atom.commands.onDidDispatch (e) =>
37 if e.target is @editorElement
40 @editorElement.classList.add("vim-mode")
42 if settings.startInInsertMode()
50 @subscriptions.dispose()
52 @deactivateInsertMode()
53 @editorElement.component?.setInputEnabled(true)
54 @editorElement.classList.remove("vim-mode")
55 @editorElement.classList.remove("normal-mode")
56 @editorElement.removeEventListener 'mouseup', @checkSelections
59 @emitter.emit 'did-destroy'
61 # Private: Creates the plugin's bindings
66 'activate-normal-mode': => @activateNormalMode()
67 'activate-linewise-visual-mode': => @activateVisualMode('linewise')
68 'activate-characterwise-visual-mode': => @activateVisualMode('characterwise')
69 'activate-blockwise-visual-mode': => @activateVisualMode('blockwise')
70 'reset-normal-mode': => @resetNormalMode()
71 'repeat-prefix': (e) => @repeatPrefix(e)
72 'reverse-selections': (e) => @reverseSelections(e)
73 'undo': (e) => @undo(e)
74 'replace-mode-backspace': => @replaceModeUndo()
75 'insert-mode-put': (e) => @insertRegister(@registerName(e))
76 'copy-from-line-above': => InsertMode.copyCharacterFromAbove(@editor, this)
77 'copy-from-line-below': => InsertMode.copyCharacterFromBelow(@editor, this)
79 @registerOperationCommands
80 'activate-insert-mode': => new Operators.Insert(@editor, this)
81 'activate-replace-mode': => new Operators.ReplaceMode(@editor, this)
82 'substitute': => [new Operators.Change(@editor, this), new Motions.MoveRight(@editor, this)]
83 'substitute-line': => [new Operators.Change(@editor, this), new Motions.MoveToRelativeLine(@editor, this)]
84 'insert-after': => new Operators.InsertAfter(@editor, this)
85 'insert-after-end-of-line': => new Operators.InsertAfterEndOfLine(@editor, this)
86 'insert-at-beginning-of-line': => new Operators.InsertAtBeginningOfLine(@editor, this)
87 'insert-above-with-newline': => new Operators.InsertAboveWithNewline(@editor, this)
88 'insert-below-with-newline': => new Operators.InsertBelowWithNewline(@editor, this)
89 'delete': => @linewiseAliasedOperator(Operators.Delete)
90 'change': => @linewiseAliasedOperator(Operators.Change)
91 'change-to-last-character-of-line': => [new Operators.Change(@editor, this), new Motions.MoveToLastCharacterOfLine(@editor, this)]
92 'delete-right': => [new Operators.Delete(@editor, this), new Motions.MoveRight(@editor, this)]
93 'delete-left': => [new Operators.Delete(@editor, this), new Motions.MoveLeft(@editor, this)]
94 'delete-to-last-character-of-line': => [new Operators.Delete(@editor, this), new Motions.MoveToLastCharacterOfLine(@editor, this)]
95 'toggle-case': => new Operators.ToggleCase(@editor, this)
96 'upper-case': => new Operators.UpperCase(@editor, this)
97 'lower-case': => new Operators.LowerCase(@editor, this)
98 'toggle-case-now': => new Operators.ToggleCase(@editor, this, complete: true)
99 'yank': => @linewiseAliasedOperator(Operators.Yank)
100 'yank-line': => [new Operators.Yank(@editor, this), new Motions.MoveToRelativeLine(@editor, this)]
101 'put-before': => new Operators.Put(@editor, this, location: 'before')
102 'put-after': => new Operators.Put(@editor, this, location: 'after')
103 'join': => new Operators.Join(@editor, this)
104 'indent': => @linewiseAliasedOperator(Operators.Indent)
105 'outdent': => @linewiseAliasedOperator(Operators.Outdent)
106 'auto-indent': => @linewiseAliasedOperator(Operators.Autoindent)
107 'increase': => new Operators.Increase(@editor, this)
108 'decrease': => new Operators.Decrease(@editor, this)
109 'move-left': => new Motions.MoveLeft(@editor, this)
110 'move-up': => new Motions.MoveUp(@editor, this)
111 'move-down': => new Motions.MoveDown(@editor, this)
112 'move-right': => new Motions.MoveRight(@editor, this)
113 'move-to-next-word': => new Motions.MoveToNextWord(@editor, this)
114 'move-to-next-whole-word': => new Motions.MoveToNextWholeWord(@editor, this)
115 'move-to-end-of-word': => new Motions.MoveToEndOfWord(@editor, this)
116 'move-to-end-of-whole-word': => new Motions.MoveToEndOfWholeWord(@editor, this)
117 'move-to-previous-word': => new Motions.MoveToPreviousWord(@editor, this)
118 'move-to-previous-whole-word': => new Motions.MoveToPreviousWholeWord(@editor, this)
119 'move-to-next-paragraph': => new Motions.MoveToNextParagraph(@editor, this)
120 'move-to-previous-paragraph': => new Motions.MoveToPreviousParagraph(@editor, this)
121 'move-to-first-character-of-line': => new Motions.MoveToFirstCharacterOfLine(@editor, this)
122 'move-to-first-character-of-line-and-down': => new Motions.MoveToFirstCharacterOfLineAndDown(@editor, this)
123 'move-to-last-character-of-line': => new Motions.MoveToLastCharacterOfLine(@editor, this)
124 'move-to-last-nonblank-character-of-line-and-down': => new Motions.MoveToLastNonblankCharacterOfLineAndDown(@editor, this)
125 'move-to-beginning-of-line': (e) => @moveOrRepeat(e)
126 'move-to-first-character-of-line-up': => new Motions.MoveToFirstCharacterOfLineUp(@editor, this)
127 'move-to-first-character-of-line-down': => new Motions.MoveToFirstCharacterOfLineDown(@editor, this)
128 'move-to-start-of-file': => new Motions.MoveToStartOfFile(@editor, this)
129 'move-to-line': => new Motions.MoveToAbsoluteLine(@editor, this)
130 'move-to-top-of-screen': => new Motions.MoveToTopOfScreen(@editorElement, this)
131 'move-to-bottom-of-screen': => new Motions.MoveToBottomOfScreen(@editorElement, this)
132 'move-to-middle-of-screen': => new Motions.MoveToMiddleOfScreen(@editorElement, this)
133 'scroll-down': => new Scroll.ScrollDown(@editorElement)
134 'scroll-up': => new Scroll.ScrollUp(@editorElement)
135 'scroll-cursor-to-top': => new Scroll.ScrollCursorToTop(@editorElement)
136 'scroll-cursor-to-top-leave': => new Scroll.ScrollCursorToTop(@editorElement, {leaveCursor: true})
137 'scroll-cursor-to-middle': => new Scroll.ScrollCursorToMiddle(@editorElement)
138 'scroll-cursor-to-middle-leave': => new Scroll.ScrollCursorToMiddle(@editorElement, {leaveCursor: true})
139 'scroll-cursor-to-bottom': => new Scroll.ScrollCursorToBottom(@editorElement)
140 'scroll-cursor-to-bottom-leave': => new Scroll.ScrollCursorToBottom(@editorElement, {leaveCursor: true})
141 'scroll-half-screen-up': => new Motions.ScrollHalfUpKeepCursor(@editorElement, this)
142 'scroll-full-screen-up': => new Motions.ScrollFullUpKeepCursor(@editorElement, this)
143 'scroll-half-screen-down': => new Motions.ScrollHalfDownKeepCursor(@editorElement, this)
144 'scroll-full-screen-down': => new Motions.ScrollFullDownKeepCursor(@editorElement, this)
145 'scroll-cursor-to-left': => new Scroll.ScrollCursorToLeft(@editorElement)
146 'scroll-cursor-to-right': => new Scroll.ScrollCursorToRight(@editorElement)
147 'select-inside-word': => new TextObjects.SelectInsideWord(@editor)
148 'select-inside-whole-word': => new TextObjects.SelectInsideWholeWord(@editor)
149 'select-inside-double-quotes': => new TextObjects.SelectInsideQuotes(@editor, '"', false)
150 'select-inside-single-quotes': => new TextObjects.SelectInsideQuotes(@editor, '\'', false)
151 'select-inside-back-ticks': => new TextObjects.SelectInsideQuotes(@editor, '`', false)
152 'select-inside-curly-brackets': => new TextObjects.SelectInsideBrackets(@editor, '{', '}', false)
153 'select-inside-angle-brackets': => new TextObjects.SelectInsideBrackets(@editor, '<', '>', false)
154 'select-inside-tags': => new TextObjects.SelectInsideBrackets(@editor, '>', '<', false)
155 'select-inside-square-brackets': => new TextObjects.SelectInsideBrackets(@editor, '[', ']', false)
156 'select-inside-parentheses': => new TextObjects.SelectInsideBrackets(@editor, '(', ')', false)
157 'select-inside-paragraph': => new TextObjects.SelectInsideParagraph(@editor, false)
158 'select-a-word': => new TextObjects.SelectAWord(@editor)
159 'select-a-whole-word': => new TextObjects.SelectAWholeWord(@editor)
160 'select-around-double-quotes': => new TextObjects.SelectInsideQuotes(@editor, '"', true)
161 'select-around-single-quotes': => new TextObjects.SelectInsideQuotes(@editor, '\'', true)
162 'select-around-back-ticks': => new TextObjects.SelectInsideQuotes(@editor, '`', true)
163 'select-around-curly-brackets': => new TextObjects.SelectInsideBrackets(@editor, '{', '}', true)
164 'select-around-angle-brackets': => new TextObjects.SelectInsideBrackets(@editor, '<', '>', true)
165 'select-around-square-brackets': => new TextObjects.SelectInsideBrackets(@editor, '[', ']', true)
166 'select-around-parentheses': => new TextObjects.SelectInsideBrackets(@editor, '(', ')', true)
167 'select-around-paragraph': => new TextObjects.SelectAParagraph(@editor, true)
168 'register-prefix': (e) => @registerPrefix(e)
169 'repeat': (e) => new Operators.Repeat(@editor, this)
170 'repeat-search': (e) => new Motions.RepeatSearch(@editor, this)
171 'repeat-search-backwards': (e) => new Motions.RepeatSearch(@editor, this).reversed()
172 'move-to-mark': (e) => new Motions.MoveToMark(@editor, this)
173 'move-to-mark-literal': (e) => new Motions.MoveToMark(@editor, this, false)
174 'mark': (e) => new Operators.Mark(@editor, this)
175 'find': (e) => new Motions.Find(@editor, this)
176 'find-backwards': (e) => new Motions.Find(@editor, this).reverse()
177 'till': (e) => new Motions.Till(@editor, this)
178 'till-backwards': (e) => new Motions.Till(@editor, this).reverse()
179 'repeat-find': (e) => new @globalVimState.currentFind.constructor(@editor, this, repeated: true) if @globalVimState.currentFind
180 'repeat-find-reverse': (e) => new @globalVimState.currentFind.constructor(@editor, this, repeated: true, reverse: true) if @globalVimState.currentFind
181 'replace': (e) => new Operators.Replace(@editor, this)
182 'search': (e) => new Motions.Search(@editor, this)
183 'reverse-search': (e) => (new Motions.Search(@editor, this)).reversed()
184 'search-current-word': (e) => new Motions.SearchCurrentWord(@editor, this)
185 'bracket-matching-motion': (e) => new Motions.BracketMatchingMotion(@editor, this)
186 'reverse-search-current-word': (e) => (new Motions.SearchCurrentWord(@editor, this)).reversed()
188 # Private: Register multiple command handlers via an {Object} that maps
189 # command names to command handler functions.
191 # Prefixes the given command names with 'vim-mode:' to reduce redundancy in
192 # the provided object.
193 registerCommands: (commands) ->
194 for commandName, fn of commands
196 @subscriptions.add(atom.commands.add(@editorElement, "vim-mode:#{commandName}", fn))
198 # Private: Register multiple Operators via an {Object} that
199 # maps command names to functions that return operations to push.
201 # Prefixes the given command names with 'vim-mode:' to reduce redundancy in
203 registerOperationCommands: (operationCommands) ->
205 for commandName, operationFn of operationCommands
207 commands[commandName] = (event) => @pushOperations(operationFn(event))
208 @registerCommands(commands)
210 # Private: Push the given operations onto the operation stack, then process
212 pushOperations: (operations) ->
213 return unless operations?
214 operations = [operations] unless _.isArray(operations)
216 for operation in operations
217 # Motions in visual mode perform their selections.
218 if @mode is 'visual' and (operation instanceof Motions.Motion or operation instanceof TextObjects.TextObject)
219 operation.execute = operation.select
221 # if we have started an operation that responds to canComposeWith check if it can compose
222 # with the operation we're going to push onto the stack
223 if (topOp = @topOperation())? and topOp.canComposeWith? and not topOp.canComposeWith(operation)
225 @emitter.emit('failed-to-compose')
228 @opStack.push(operation)
230 # If we've received an operator in visual mode, mark the current
231 # selection as the motion to operate on.
232 if @mode is 'visual' and operation instanceof Operators.Operator
233 @opStack.push(new Motions.CurrentSelection(@editor, this))
237 onDidFailToCompose: (fn) ->
238 @emitter.on('failed-to-compose', fn)
240 onDidDestroy: (fn) ->
241 @emitter.on('did-destroy', fn)
243 # Private: Removes all operations from the stack.
251 @activateNormalMode()
253 # Private: Processes the command if the last operation is complete.
257 unless @opStack.length > 0
260 unless @topOperation().isComplete()
261 if @mode is 'normal' and @topOperation() instanceof Operators.Operator
262 @activateOperatorPendingMode()
265 poppedOperation = @opStack.pop()
268 @topOperation().compose(poppedOperation)
271 if (e instanceof Operators.OperatorError) or (e instanceof Motions.MotionError)
276 @history.unshift(poppedOperation) if poppedOperation.isRecordable()
277 poppedOperation.execute()
279 # Private: Fetches the last operation.
281 # Returns the last operation.
285 # Private: Fetches the value of a given register.
287 # name - The name of the register to fetch.
289 # Returns the value of the given register or undefined if it hasn't
291 getRegister: (name) ->
293 name = settings.defaultRegister()
294 if name in ['*', '+']
295 text = atom.clipboard.read()
296 type = Utils.copyType(text)
299 text = @editor.getURI()
300 type = Utils.copyType(text)
302 else if name is "_" # Blackhole always returns nothing
304 type = Utils.copyType(text)
307 @globalVimState.registers[name.toLowerCase()]
309 # Private: Fetches the value of a given mark.
311 # name - The name of the mark to fetch.
313 # Returns the value of the given mark or undefined if it hasn't
317 @marks[name].getBufferRange().start
321 # Private: Sets the value of a given register.
323 # name - The name of the register to fetch.
324 # value - The value to set the register to.
327 setRegister: (name, value) ->
329 name = settings.defaultRegister()
330 if name in ['*', '+']
331 atom.clipboard.write(value.text)
333 # Blackhole register, nothing to do
334 else if /^[A-Z]$/.test(name)
335 @appendRegister(name.toLowerCase(), value)
337 @globalVimState.registers[name] = value
340 # Private: append a value into a given register
341 # like setRegister, but appends the value
342 appendRegister: (name, value) ->
343 register = @globalVimState.registers[name] ?=
346 if register.type is 'linewise' and value.type isnt 'linewise'
347 register.text += value.text + '\n'
348 else if register.type isnt 'linewise' and value.type is 'linewise'
349 register.text += '\n' + value.text
350 register.type = 'linewise'
352 register.text += value.text
354 # Private: Sets the value of a given mark.
356 # name - The name of the mark to fetch.
357 # pos {Point} - The value to set the mark to.
360 setMark: (name, pos) ->
361 # check to make sure name is in [a-z] or is `
362 if (charCode = name.charCodeAt(0)) >= 96 and charCode <= 122
363 marker = @editor.markBufferRange(new Range(pos, pos), {invalidate: 'never', persistent: false})
364 @marks[name] = marker
366 # Public: Append a search to the search history.
368 # Motions.Search - The confirmed search motion to append
371 pushSearchHistory: (search) ->
372 @globalVimState.searchHistory.unshift search
374 # Public: Get the search history item at the given index.
376 # index - the index of the search history item
378 # Returns a search motion
379 getSearchHistoryItem: (index = 0) ->
380 @globalVimState.searchHistory[index]
382 ##############################################################################
384 ##############################################################################
386 # Private: Used to enable normal mode.
389 activateNormalMode: ->
390 @deactivateInsertMode()
391 @deactivateVisualMode()
396 @changeModeClass('normal-mode')
399 selection.clear(autoscroll: false) for selection in @editor.getSelections()
400 @ensureCursorsWithinLine()
404 # TODO: remove this method and bump the `vim-mode` service version number.
405 activateCommandMode: ->
406 Grim.deprecate("Use ::activateNormalMode instead")
407 @activateNormalMode()
409 # Private: Used to enable insert mode.
412 activateInsertMode: (subtype = null) ->
414 @editorElement.component.setInputEnabled(true)
415 @setInsertionCheckpoint()
417 @changeModeClass('insert-mode')
420 activateReplaceMode: ->
421 @activateInsertMode('replace')
422 @replaceModeCounter = 0
423 @editorElement.classList.add('replace-mode')
424 @subscriptions.add @replaceModeListener = @editor.onWillInsertText @replaceModeInsertHandler
425 @subscriptions.add @replaceModeUndoListener = @editor.onDidInsertText @replaceModeUndoHandler
427 replaceModeInsertHandler: (event) =>
428 chars = event.text?.split('') or []
429 selections = @editor.getSelections()
431 continue if char is '\n'
432 for selection in selections
433 selection.delete() unless selection.cursor.isAtEndOfLine()
436 replaceModeUndoHandler: (event) =>
437 @replaceModeCounter++
440 if @replaceModeCounter > 0
444 @replaceModeCounter--
446 setInsertionCheckpoint: ->
447 @insertionCheckpoint = @editor.createCheckpoint() unless @insertionCheckpoint?
449 deactivateInsertMode: ->
450 return unless @mode in [null, 'insert']
451 @editorElement.component.setInputEnabled(false)
452 @editorElement.classList.remove('replace-mode')
453 @editor.groupChangesSinceCheckpoint(@insertionCheckpoint)
454 changes = getChangesSinceCheckpoint(@editor.buffer, @insertionCheckpoint)
455 item = @inputOperator(@history[0])
456 @insertionCheckpoint = null
458 item.confirmChanges(changes)
459 for cursor in @editor.getCursors()
460 cursor.moveLeft() unless cursor.isAtBeginningOfLine()
461 if @replaceModeListener?
462 @replaceModeListener.dispose()
463 @subscriptions.remove @replaceModeListener
464 @replaceModeListener = null
465 @replaceModeUndoListener.dispose()
466 @subscriptions.remove @replaceModeUndoListener
467 @replaceModeUndoListener = null
469 deactivateVisualMode: ->
470 return unless @mode is 'visual'
471 for selection in @editor.getSelections()
472 selection.cursor.moveLeft() unless (selection.isEmpty() or selection.isReversed())
474 # Private: Get the input operator that needs to be told about about the
475 # typed undo transaction in a recently completed operation, if there
477 inputOperator: (item) ->
478 return item unless item?
479 return item if item.inputOperator?()
480 return item.composedObject if item.composedObject?.inputOperator?()
482 # Private: Used to enable visual mode.
484 # type - One of 'characterwise', 'linewise' or 'blockwise'
487 activateVisualMode: (type) ->
488 # Already in 'visual', this means one of following command is
489 # executed within `vim-mode.visual-mode`
490 # * activate-blockwise-visual-mode
491 # * activate-characterwise-visual-mode
492 # * activate-linewise-visual-mode
495 @activateNormalMode()
499 if @submode is 'linewise'
500 for selection in @editor.getSelections()
501 # Keep original range as marker's property to get back
503 # Since selectLine lost original cursor column.
504 originalRange = selection.getBufferRange()
505 selection.marker.setProperties({originalRange})
506 [start, end] = selection.getBufferRowRange()
507 selection.selectLine(row) for row in [start..end]
509 else if @submode in ['characterwise', 'blockwise']
510 # Currently, 'blockwise' is not yet implemented.
511 # So treat it as characterwise.
512 # Recover original range.
513 for selection in @editor.getSelections()
514 {originalRange} = selection.marker.getProperties()
516 [startRow, endRow] = selection.getBufferRowRange()
517 originalRange.start.row = startRow
518 originalRange.end.row = endRow
519 selection.setBufferRange(originalRange)
521 @deactivateInsertMode()
524 @changeModeClass('visual-mode')
526 if @submode is 'linewise'
527 @editor.selectLinesContainingCursors()
528 else if @editor.getSelectedText() is ''
529 @editor.selectRight()
533 # Private: Used to re-enable visual mode
535 @activateVisualMode(@submode)
537 # Private: Used to enable operator-pending mode.
538 activateOperatorPendingMode: ->
539 @deactivateInsertMode()
540 @mode = 'operator-pending'
542 @changeModeClass('operator-pending-mode')
546 changeModeClass: (targetMode) ->
547 for mode in ['normal-mode', 'insert-mode', 'visual-mode', 'operator-pending-mode']
548 if mode is targetMode
549 @editorElement.classList.add(mode)
551 @editorElement.classList.remove(mode)
553 # Private: Resets the normal mode back to it's initial state.
558 @editor.clearSelections()
559 @activateNormalMode()
561 # Private: A generic way to create a Register prefix based on the event.
563 # e - The event that triggered the Register prefix.
566 registerPrefix: (e) ->
567 new Prefixes.Register(@registerName(e))
569 # Private: Gets a register name from a keyboard event
573 # Returns the name of the register
575 keyboardEvent = e.originalEvent?.originalEvent ? e.originalEvent
576 name = atom.keymaps.keystrokeForKeyboardEvent(keyboardEvent)
577 if name.lastIndexOf('shift-', 0) is 0
581 # Private: A generic way to create a Number prefix based on the event.
583 # e - The event that triggered the Number prefix.
587 keyboardEvent = e.originalEvent?.originalEvent ? e.originalEvent
588 num = parseInt(atom.keymaps.keystrokeForKeyboardEvent(keyboardEvent))
589 if @topOperation() instanceof Prefixes.Repeat
590 @topOperation().addDigit(num)
595 @pushOperations(new Prefixes.Repeat(num))
597 reverseSelections: ->
598 reversed = not @editor.getLastSelection().isReversed()
599 for selection in @editor.getSelections()
600 selection.setBufferRange(selection.getBufferRange(), {reversed})
602 # Private: Figure out whether or not we are in a repeat sequence or we just
603 # want to move to the beginning of the line. If we are within a repeat
604 # sequence, we pass control over to @repeatPrefix.
606 # e - The triggered event.
608 # Returns new motion or nothing.
610 if @topOperation() instanceof Prefixes.Repeat
614 new Motions.MoveToBeginningOfLine(@editor, this)
616 # Private: A generic way to handle Operators that can be repeated for
617 # their linewise form.
619 # constructor - The constructor of the operator.
622 linewiseAliasedOperator: (constructor) ->
623 if @isOperatorPending(constructor)
624 new Motions.MoveToRelativeLine(@editor, this)
626 new constructor(@editor, this)
628 # Private: Check if there is a pending operation of a certain type, or
629 # if there is any pending operation, if no type given.
631 # constructor - The constructor of the object type you're looking for.
633 isOperatorPending: (constructor) ->
636 return op if op instanceof constructor
642 @statusBarManager.update(@mode, @submode)
644 # Private: insert the contents of the register in the editor
646 # name - the name of the register to insert
649 insertRegister: (name) ->
650 text = @getRegister(name)?.text
651 @editor.insertText(text) if text?
653 # Private: ensure the mode follows the state of selections
655 return unless @editor?
656 if @editor.getSelections().every((selection) -> selection.isEmpty())
657 @ensureCursorsWithinLine() if @mode is 'normal'
658 @activateNormalMode() if @mode is 'visual'
660 @activateVisualMode('characterwise') if @mode is 'normal'
662 # Private: ensure the cursor stays within the line as appropriate
663 ensureCursorsWithinLine: =>
664 for cursor in @editor.getCursors()
665 {goalColumn} = cursor
666 if cursor.isAtEndOfLine() and not cursor.isAtBeginningOfLine()
668 cursor.goalColumn = goalColumn
670 @editor.mergeCursors()
672 # This uses private APIs and may break if TextBuffer is refactored.
673 # Package authors - copy and paste this code at your own risk.
674 getChangesSinceCheckpoint = (buffer, checkpoint) ->
677 if (index = history.getCheckpointIndex(checkpoint))?
678 history.undoStack.slice(index)