     else
       lastVisibleRow
 
+  # Jim's block cursor is not considered by Ace to be part of the selection
+  # unless the selection is backwards.  This makes the cursor part of the
+  # selection.  Used just before the selection is acted upon, while an
+  # `Operation` with a non-`exclusive` `Motion` is executing, for example.
   includeCursorInSelection: ->
     if not @editor.selection.isBackwards()
       @editor.selection.selectRight() unless beyondLineEnd(@editor)

{UndoManager} = require 'ace/undomanager'
Jim           = require './jim'

class Adaptor
  constructor: (@editor) ->

  atLineEnd = (editor, beyond) ->
    selectionLead = editor.selection.getSelectionLead()
    lineLength = editor.selection.doc.getLine(selectionLead.row).length

    else if prevMode?.name is 'replace'
      @markUndoPoint 'jim:replace:end'

  # Vim's undo is particularly useful because it's idea of an atomic edit is
  # clear to the user.  One `Command` is undone each time `u` is pressed.  That
  # means all text entered between hitting `i` and hitting `<esc>` is undone as
  # one atomic edit.
  #
  # To match Vim's undo granularity, Jim pushes "bookmarks" onto the undo stack
  # to indicate when an insert starts or ends, for example.  This helps us avoid
  # having to record all keystrokes made while in insert or replace mode.
  markUndoPoint: (markName) ->
    @editor.session.getUndoManager().execute args: [markName, @editor.session]

  # turns overwrite mode on or off (used for Jim's replace mode)
  setOverwriteMode: (active) -> @editor.setOverwrite active

  # clears the selection, optionally positioning the at its beginning
  clearSelection: (beginning) ->
    if beginning and not @editor.selection.isBackwards()
      {row, column} = @editor.selection.getSelectionAnchor()
