1 # This file contains functions helping to upgrade to a newer version of VimFx
2 # without breaking backwards-compatibility. These are used in migrations.coffee.
4 notation = require('vim-like-key-notation')
5 prefs = require('./prefs')
6 utils = require('./utils')
8 applyMigrations = (migrations) ->
9 for migration, index in migrations
10 pref = "migration.#{index}.applied"
11 # This allows to manually choose migrations to apply. Be careful, though,
12 # since some migrations might have to run in order!
13 unless prefs.has(pref) and prefs.get(pref)
18 commaSeparatedList = /.[^,]*,?/g
20 commaSeparatedListItem = ///^
22 (?: (Shift) | ([acm])+ )
29 convertKey = (keyStr) ->
30 return (keyStr.trim().match(commaSeparatedList) ? []).map((part) ->
31 [match, shift, modifiers, key] = part.match(commaSeparatedListItem)
33 return notation.stringify({
35 shiftKey: Boolean(shift)
36 altKey: 'a' in modifiers
37 ctrlKey: 'c' in modifiers
38 metaKey: 'm' in modifiers
42 convertPattern = (pattern) ->
43 return utils.regexEscape(pattern)
44 .replace(/\\\*/g, '.*')
46 .replace(/\s+/g, '\\s+')
48 splitListString = (str) ->
49 return str.split(/\s*,[\s,]*/)