]> git.gir.st - VimFx.git/blob - extension/lib/migrations.coffee
Enable the `no_implicit_braces` CoffeeLint rule
[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 # This file contains a list of functions that upgrade certain parts of VimFx
21 # from an old format to a new one, without breaking backwards compatibility.
22
23 legacy = require('./legacy')
24 prefs = require('./prefs')
25
26 migrations = []
27
28 migrations[0] = ->
29 # coffeelint: disable=no_implicit_braces
30
31 conversions =
32 'focus': 'normal.focus_location_bar'
33 'focus_search': 'normal.focus_search_bar'
34 'paste': 'normal.paste_and_go'
35 'paste_tab': 'normal.paste_and_go_in_tab'
36 'marker_yank': 'normal.follow_copy'
37 'marker_focus': 'normal.follow_focus'
38 'yank': 'normal.copy_current_url'
39 'reload': 'normal.reload'
40 'reload_force': 'normal.reload_force'
41 'reload_all': 'normal.reload_all'
42 'reload_all_force': 'normal.reload_all_force'
43 'stop': 'normal.stop'
44 'stop_all': 'normal.stop_all'
45
46 'scroll_to_top': 'normal.scroll_to_top'
47 'scroll_to_bottom': 'normal.scroll_to_bottom'
48 'scroll_to_left': 'normal.scroll_to_left'
49 'scroll_to_right': 'normal.scroll_to_right'
50 'scroll_down': 'normal.scroll_down'
51 'scroll_up': 'normal.scroll_up'
52 'scroll_left': 'normal.scroll_left'
53 'scroll_right': 'normal.scroll_right'
54 'scroll_half_page_down': 'normal.scroll_half_page_down'
55 'scroll_half_page_up': 'normal.scroll_half_page_up'
56 'scroll_page_down': 'normal.scroll_page_down'
57 'scroll_page_up': 'normal.scroll_page_up'
58
59 'open_tab': 'normal.tab_new'
60 'tab_prev': 'normal.tab_select_previous'
61 'tab_next': 'normal.tab_select_next'
62 'tab_move_left': 'normal.tab_move_backward'
63 'tab_move_right': 'normal.tab_move_forward'
64 'home': 'normal.go_home'
65 'tab_first': 'normal.tab_select_first'
66 'tab_first_non_pinned': 'normal.tab_select_first_non_pinned'
67 'tab_last': 'normal.tab_select_last'
68 'toggle_pin_tab': 'normal.tab_toggle_pinned'
69 'duplicate_tab': 'normal.tab_duplicate'
70 'close_tabs_to_end': 'normal.tab_close_to_end'
71 'close_other_tabs': 'normal.tab_close_other'
72 'close_tab': 'normal.tab_close'
73 'restore_tab': 'normal.tab_restore'
74
75 'follow': 'normal.follow'
76 'follow_in_tab': 'normal.follow_in_tab'
77 'follow_in_focused_tab': 'normal.follow_in_focused_tab'
78 'follow_multiple': 'normal.follow_multiple'
79 'follow_previous': 'normal.follow_previous'
80 'follow_next': 'normal.follow_next'
81 'text_input': 'normal.text_input'
82 'go_up_path': 'normal.go_up_path'
83 'go_to_root': 'normal.go_to_root'
84 'back': 'normal.history_back'
85 'forward': 'normal.history_forward'
86
87 'find': 'normal.find'
88 'find_hl': 'normal.find_highlight_all'
89 'find_next': 'normal.find_next'
90 'find_prev': 'normal.find_previous'
91 'insert_mode': 'normal.enter_mode_ignore'
92 'quote': 'normal.quote'
93 'help': 'normal.help'
94 'dev': 'normal.dev'
95 'Esc': 'normal.esc'
96
97 'mode_insert_exit': 'ignore.exit'
98
99 'mode_hints_exit': 'hints.exit'
100 'mode_hints_rotate_markers_forward': 'hints.rotate_markers_forward'
101 'mode_hints_rotate_markers_backward': 'hints.rotate_markers_backward'
102 'mode_hints_delete_hint_char': 'hints.delete_hint_char'
103
104 'mode_find_exit': 'find.exit'
105
106 # coffeelint: enable=no_implicit_braces
107
108 convert = (value) ->
109 keys = try JSON.parse(value)
110 keys = [] unless Array.isArray(keys)
111 for key, index in keys when typeof key == 'string'
112 keys[index] = legacy.convertKey(key)
113 return keys.map((key) -> key.join('')).join(' ')
114
115 for name, newName of conversions
116 pref = "commands.#{name}.keys"
117 prefs.set("mode.#{newName}", convert(prefs.get(pref))) if prefs.has(pref)
118 return
119
120 migrations[1] = ->
121 pref = 'black_list'
122 return unless prefs.has(pref)
123 blacklist = prefs.get(pref)
124 prefs.set(pref, legacy.splitListString(blacklist).join(' '))
125
126 migrations[2] = ->
127 convert = (pref) ->
128 return unless prefs.has(pref)
129 patterns = prefs.get(pref)
130 converted = legacy.splitListString(patterns)
131 .map(legacy.convertPattern)
132 .join(' ')
133 prefs.set(pref, converted)
134
135 convert('prev_patterns')
136 convert('next_patterns')
137
138 migrations[3] = ->
139 pref = 'mode.normal.esc'
140 return unless prefs.has(pref)
141 prefs.set(pref, prefs.get(pref).replace(
142 /(^|\s)(?!(?:<late>)?<force>)(?=\S)/g,
143 '$1<force>'
144 ))
145
146 migrations[4] = ->
147 pref = 'last_scroll_position_mark'
148 return unless prefs.has(pref)
149 prefs.set('scroll.last_position_mark', prefs.get(pref))
150
151 module.exports = migrations
Imprint / Impressum