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