MCPcopy
hub / github.com/peco/peco / ApplyKeybinding

Method ApplyKeybinding

keymap.go:159–204  ·  view source on GitHub ↗

ApplyKeybinding applies all of the custom key bindings on top of the default key bindings

()

Source from the content-addressed store, hash-verified

157// ApplyKeybinding applies all of the custom key bindings on top of
158// the default key bindings
159func (km *Keymap) ApplyKeybinding() error {
160 k := km.seq
161 k.Clear()
162
163 // Copy the map
164 kb := map[string]Action{}
165 maps.Copy(kb, defaultKeyBinding)
166
167 // munge the map using config
168 for s, as := range km.Config {
169 if as == "-" {
170 delete(kb, s)
171 continue
172 }
173
174 v, err := km.resolveActionName(as, 0)
175 if err != nil {
176 return fmt.Errorf("failed to resolve action name %s: %w", as, err)
177 }
178 kb[s] = v
179 }
180
181 // now compile using kb
182 // there's no need to do this, but we sort keys here just to make
183 // debugging easier
184 keys := make([]string, 0, len(kb))
185 for s := range kb {
186 keys = append(keys, s)
187 }
188 sort.Strings(keys)
189
190 for _, s := range keys {
191 a := kb[s]
192 list, err := keyseq.ToKeyList(s)
193 if err != nil {
194 return fmt.Errorf("unknown key %s: %w", s, err)
195 }
196
197 k.Add(list, a)
198 }
199
200 if err := k.Compile(); err != nil {
201 return fmt.Errorf("failed to compile key binding patterns: %w", err)
202 }
203 return nil
204}

Callers 1

populateKeymapMethod · 0.95

Calls 6

resolveActionNameMethod · 0.95
ToKeyListFunction · 0.92
CopyMethod · 0.80
ClearMethod · 0.65
AddMethod · 0.65
CompileMethod · 0.65

Tested by

no test coverage detected