jim.coffee | |
---|---|
An instance of | Keymap = require './keymap'
{GoToLine} = require './motions'
class Jim
@VERSION: '0.2.0-pre'
constructor: (@adaptor) ->
@command = null
@registers = {}
@keymap = Keymap.getDefault()
@setMode 'normal'
modes: require './modes' |
Change Jim's mode to | setMode: (modeName, modeState) ->
console.log 'setMode', modeName, modeState if @debugMode
prevMode = @mode
if modeName is prevMode?.name
return unless modeState
@mode[key] = value for own key, value of modeState
else
@mode = modeState or {}
@mode.name = modeName
@adaptor.onModeChange? prevMode, @mode
switch prevMode?.name
when 'insert'
@adaptor.moveLeft() |
Get info about what was inserted so the insert "remembers" how to repeat itself. | @lastCommand.repeatableInsert = @adaptor.lastInsert()
when 'replace'
@adaptor.setOverwriteMode off |
Pressing escape blows away all the state. | onEscape: ->
@setMode 'normal'
@command = null
@commandPart = '' # just in case...
@adaptor.clearSelection() |
When a key is pressed, let the current mode figure out what to do about it. | onKeypress: (keys) -> @modes[@mode.name].onKeypress.call this, keys |
Delete the selected text and put it in the default register. | deleteSelection: (exclusive, linewise) ->
@registers['"'] = @adaptor.deleteSelection exclusive, linewise
|
Yank the selected text into the default register. | yankSelection: (exclusive, linewise) ->
@registers['"'] = @adaptor.selectionText exclusive, linewise
@adaptor.clearSelection true
module.exports = Jim
|