]> git.gir.st - VimFx.git/blob - extension/lib/legacy.coffee
Recognozie more ARIA roles as clickable
[VimFx.git] / extension / lib / legacy.coffee
1 ###
2 # Copyright Simon Lydell 2015.
3 #
4 # This file is part of VimFx.
5 #
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.
10 #
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.
15 #
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/>.
18 ###
19
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.
22
23 notation = require('vim-like-key-notation')
24 prefs = require('./prefs')
25 utils = require('./utils')
26
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)
33 migration()
34 prefs.set(pref, true)
35 return
36
37 commaSeparatedList = /.[^,]*,?/g
38
39 commaSeparatedListItem = ///^
40 (?:
41 (?: (Shift) | ([acm])+ )
42 -
43 )?
44 (.+?)
45 ,?
46 $///
47
48 convertKey = (keyStr) ->
49 return (keyStr.trim().match(commaSeparatedList) ? []).map((part) ->
50 [match, shift, modifiers, key] = part.match(commaSeparatedListItem)
51 modifiers ?= ''
52 return notation.stringify({
53 key
54 shiftKey: Boolean(shift)
55 altKey: 'a' in modifiers
56 ctrlKey: 'c' in modifiers
57 metaKey: 'm' in modifiers
58 })
59 )
60
61 convertPattern = (pattern) ->
62 return utils.regexEscape(pattern)
63 .replace(/\\\*/g, '.*')
64 .replace(/!/g, '.')
65 .replace(/\s+/g, '\\s+')
66
67 splitListString = (str) ->
68 return str.split(/\s*,[\s,]*/)
69
70 module.exports = {
71 applyMigrations
72 convertKey
73 convertPattern
74 splitListString
75 }
Imprint / Impressum