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