]> git.gir.st - VimFx.git/blob - extension/lib/migrations.coffee
Rework custom shortcut prefs
[VimFx.git] / extension / lib / migrations.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 legacy = require('./legacy')
21 { getPref
22 , setPref
23 , isPrefSet} = require('./prefs')
24
25 applyMigrations = (migrations) ->
26 for migration, index in migrations
27 pref = "migration.#{ index }.applied"
28 # This allows to manually choose migrations to apply. Be careful, though,
29 # since some migrations might have to run in order!
30 unless isPrefSet(pref) and getPref(pref)
31 migration()
32 setPref(pref, true)
33 return
34
35 migrations = []
36
37 migrations[0] = ->
38 conversions =
39 'focus': 'normal.focus_location_bar'
40 'focus_search': 'normal.focus_search_bar'
41 'paste': 'normal.paste_and_go'
42 'paste_tab': 'normal.paste_and_go_in_tab'
43 'marker_yank': 'normal.follow_copy'
44 'marker_focus': 'normal.follow_focus'
45 'yank': 'normal.copy_current_url'
46 'reload': 'normal.reload'
47 'reload_force': 'normal.reload_force'
48 'reload_all': 'normal.reload_all'
49 'reload_all_force': 'normal.reload_all_force'
50 'stop': 'normal.stop'
51 'stop_all': 'normal.stop_all'
52
53 'scroll_to_top': 'normal.scroll_to_top'
54 'scroll_to_bottom': 'normal.scroll_to_bottom'
55 'scroll_to_left': 'normal.scroll_to_left'
56 'scroll_to_right': 'normal.scroll_to_right'
57 'scroll_down': 'normal.scroll_down'
58 'scroll_up': 'normal.scroll_up'
59 'scroll_left': 'normal.scroll_left'
60 'scroll_right': 'normal.scroll_right'
61 'scroll_half_page_down': 'normal.scroll_half_page_down'
62 'scroll_half_page_up': 'normal.scroll_half_page_up'
63 'scroll_page_down': 'normal.scroll_page_down'
64 'scroll_page_up': 'normal.scroll_page_up'
65
66 'open_tab': 'normal.tab_new'
67 'tab_prev': 'normal.tab_select_previous'
68 'tab_next': 'normal.tab_select_next'
69 'tab_move_left': 'normal.tab_move_backward'
70 'tab_move_right': 'normal.tab_move_forward'
71 'home': 'normal.go_home'
72 'tab_first': 'normal.tab_select_first'
73 'tab_first_non_pinned': 'normal.tab_select_first_non_pinned'
74 'tab_last': 'normal.tab_select_last'
75 'toggle_pin_tab': 'normal.tab_toggle_pinned'
76 'duplicate_tab': 'normal.tab_duplicate'
77 'close_tabs_to_end': 'normal.tab_close_to_end'
78 'close_other_tabs': 'normal.tab_close_other'
79 'close_tab': 'normal.tab_close'
80 'restore_tab': 'normal.tab_restore'
81
82 'follow': 'normal.follow'
83 'follow_in_tab': 'normal.follow_in_tab'
84 'follow_in_focused_tab': 'normal.follow_in_focused_tab'
85 'follow_multiple': 'normal.follow_multiple'
86 'follow_previous': 'normal.follow_previous'
87 'follow_next': 'normal.follow_next'
88 'text_input': 'normal.text_input'
89 'go_up_path': 'normal.go_up_path'
90 'go_to_root': 'normal.go_to_root'
91 'back': 'normal.history_back'
92 'forward': 'normal.history_forward'
93
94 'find': 'normal.find'
95 'find_hl': 'normal.find_highlight_all'
96 'find_next': 'normal.find_next'
97 'find_prev': 'normal.find_previous'
98 'insert_mode': 'normal.enter_mode_insert'
99 'quote': 'normal.quote'
100 'help': 'normal.help'
101 'dev': 'normal.dev'
102 'Esc': 'normal.esc'
103
104 'mode_insert_exit': 'insert.exit'
105
106 'mode_hints_exit': 'hints.exit'
107 'mode_hints_rotate_markers_forward': 'hints.rotate_markers_forward'
108 'mode_hints_rotate_markers_backward': 'hints.rotate_markers_backward'
109 'mode_hints_delete_hint_char': 'hints.delete_hint_char'
110
111 'mode_find_exit': 'find.exit'
112
113
114 convert = (value) ->
115 keys =
116 try JSON.parse(value)
117 catch then []
118 for key, index in keys when typeof key == 'string'
119 keys[index] = legacy.convertKey(key)
120 return keys.map((key) -> key.join('')).join(' ')
121
122 for name, newName of conversions
123 pref = "commands.#{ name }.keys"
124 setPref("mode.#{ newName }", convert(getPref(pref))) if isPrefSet(pref)
125 return
126
127 exports.applyMigrations = applyMigrations
128 exports.migrations = migrations
Imprint / Impressum