2 # Copyright Simon Lydell 2015.
4 # This file is part of VimFx.
6 # VimFx is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # VimFx is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with VimFx. If not, see <http://www.gnu.org/licenses/>.
20 # This file contains functions helping to upgrade to a newer version of VimFx
21 # without breaking backwards-compatibility. These are used in migrations.coffee.
23 notation = require('vim-like-key-notation')
24 prefs = require('./prefs')
25 utils = require('./utils')
27 applyMigrations = (migrations) ->
28 for migration, index in migrations
29 pref = "migration.#{ index }.applied"
30 # This allows to manually choose migrations to apply. Be careful, though,
31 # since some migrations might have to run in order!
32 unless prefs.has(pref) and prefs.get(pref)
37 commaSeparatedList = /.[^,]*,?/g
39 commaSeparatedListItem = ///^
41 (?: (Shift) | ([acm])+ )
48 convertKey = (keyStr) ->
49 return keyStr.match(commaSeparatedList).map((part) ->
50 [match, shift, modifiers, key] = part.match(commaSeparatedListItem)
52 return notation.stringify({
54 shiftKey: Boolean(shift)
55 altKey: 'a' in modifiers
56 ctrlKey: 'c' in modifiers
57 metaKey: 'm' in modifiers
61 convertPattern = (pattern) ->
62 return utils.regexEscape(pattern)
63 .replace(/\\\*/g, '.*')
65 .replace(/\s+/g, '\\s+')
67 splitListString = (str) ->
68 return str.split(/\s*,[\s,]*/)