blukat29 / vimedu

Learn basics of vim interactively.
MIT License
1 stars 1 forks source link

[codemirror] buildKeyMap #2

Closed blukat29 closed 10 years ago

blukat29 commented 10 years ago

Requirements:

  1. Use live keys sets (do not use defaultKeyMap[]. overrides from API calls should be considered)
  2. One function to build (Mode, Key) -> (command name or command type)
  3. Another function to build (command type [, keybuf]) -> (command candidates)
blukat29 commented 10 years ago

vim.js internal structure

var defaultKeyMap[] = {
    { keys: ['<Left>'], type: 'keyToKey', toKeys: ['h'] },
    { keys: ['H'], type: 'motion', motion: 'moveToTopLine', ... },
    { keys: ['g', 'g'], type: 'motion', motion: 'moveToLineOrEdgeOfDocument', ... },
    { keys: ['d'], type: 'operator', operator: 'delete' },
    { keys: ['x'], type: 'operatorMotion', operator: 'delete', motion: 'moveByCharacters', ... },
    { keys: ['i'], type: 'action', action: 'enterInsertMode', ... },
    { keys: ['u'], type: 'action', action: 'changeCase', context: 'visual', ... },
    { keys: ['i', 'character'], type: 'motion', motion: 'textObjectManipulation', ... },
    { keys: ['/'], type: 'search', ... },
    { keys: [':'], type: 'ex' },
];
blukat29 commented 10 years ago

Try not to touch vim.js. Modifying it can lead to unexpected result since vim.js is really large. So we just implement Vim.buildKeyMap() as returning defaultKeymap[]. This works because modifying vim keymaps via map and unmap command modifies defaultKeymap. That is, defaultKeymap holds the up-to-date set of key maps.