keybindingResolver.ts ×14

Frontier kind: Code frontier

unlabeled · c_52a23bb076ac

21 tests · 7648 LOC · 37 files · introduces 0 tests · 46 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
14 ranges46 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
1152 ranges7648 lines · 37 files · Browse complete extent
All tests (intent)
21 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 46 introduced LOC across 14 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/keybinding/common/keybindingResolver.ts 46 introduced LOC · 14 ranges

Open complete file

30 export const NoMatchingKb: ResolutionResult = { kind: ResultKind.NoMatchingKb };
31 const MoreChordsNeeded: ResolutionResult = { kind: ResultKind.MoreChordsNeeded };
32 > function KbFound(commandId: string | null, commandArgs: any, isBubble: boolean): ResolutionResult { keybindingResolver.ts
33 > return { kind: ResultKind.KbFound, commandId, commandArgs, isBubble };
34 > }
35
36 //#endregion
319 */
320 public resolve(context: IContext, currentChords: string[], keypress: string): ResolutionResult {
322 > const pressedChords = [...currentChords, keypress];
323 >
324 > this._log(`| Resolving ${pressedChords}`);
325 >
326 > const kbCandidates = this._map.get(pressedChords[0]);
327 > if (kbCandidates === undefined) {
328 // No bindings with such 0-th chord
329 this._log(`\\ No keybinding entries.`);
330 return NoMatchingKb;
331 }
333 > let lookupMap: ResolvedKeybindingItem[] | null = null;
334 >
335 > if (pressedChords.length < 2) {
336 > lookupMap = kbCandidates;
337 > } else {
338 // Fetch all chord bindings for `currentChords`
339 lookupMap = [];
358 }
359 }
361 > // check there's a keybinding with a matching when clause
362 > const result = this._findCommand(context, lookupMap);
363 > if (!result) {
364 this._log(`\\ From ${lookupMap.length} keybinding entries, no when clauses matched the context.`);
365 return NoMatchingKb;
366 }
368 > // check we got all chords necessary to be sure a particular keybinding needs to be invoked
369 > if (pressedChords.length < result.chords.length) {
370 // The chord sequence is not complete
371 this._log(`\\ From ${lookupMap.length} keybinding entries, awaiting ${result.chords.length - pressedChords.length} more chord(s), when: ${printWhenExplanation(result.when)}, source: ${printSourceExplanation(result)}.`);
372 return MoreChordsNeeded;
373 }
375 > this._log(`\\ From ${lookupMap.length} keybinding entries, matched ${result.command}, when: ${printWhenExplanation(result.when)}, source: ${printSourceExplanation(result)}.`);
376 >
377 > return KbFound(result.command, result.commandArgs, result.bubble);
378 > }
379
380 private _findCommand(context: IContext, matches: ResolvedKeybindingItem[]): ResolvedKeybindingItem | null {
381 > for (let i = matches.length - 1; i >= 0; i--) { keybindingResolver.ts
382 > const k = matches[i];
383 >
384 > if (!KeybindingResolver._contextMatchesRules(context, k.when)) {
385 continue;
386 }
388 > return k;
389 > }
390
391 return null;
393
394 private static _contextMatchesRules(context: IContext, rules: ContextKeyExpression | null | undefined): boolean {
395 > if (!rules) { keybindingResolver.ts
396 return true;
397 }
398 return rules.evaluate(context);
400 }
401
402 > function printWhenExplanation(when: ContextKeyExpression | undefined): string { keybindingResolver.ts
403 > if (!when) {
404 return `no when condition`;
405 }
407 }
408
409 > function printSourceExplanation(kb: ResolvedKeybindingItem): string { keybindingResolver.ts
410 > return (
411 > kb.extensionId
412 ? (kb.isBuiltinExtension ? `built-in extension ${kb.extensionId}` : `user extension ${kb.extensionId}`)
413 > : (kb.isDefault ? `built-in` : `user`) keybindingResolver.ts
414 > );
415 > }