MCPcopy Create free account
hub / github.com/tensorflow/tensorboard / sendKey

Function sendKey

tensorboard/webapp/testing/dom.ts:51–168  ·  view source on GitHub ↗
(
  fixture: ComponentFixture<T>,
  eventTarget: DebugElement,
  args: SendKeyArgs
)

Source from the content-addressed store, hash-verified

49 * presses.
50 */
51export function sendKey<T>(
52 fixture: ComponentFixture<T>,
53 eventTarget: DebugElement,
54 args: SendKeyArgs
55) {
56 const {prevString, key, startingCursorIndex} = args;
57
58 const el = eventTarget.nativeElement;
59 const canSetCursor =
60 el instanceof HTMLInputElement &&
61 el.type !== 'date' &&
62 el.type !== 'number';
63
64 let nextString: string;
65 let nextCursorIndex: number;
66 // KeyCode is deprecated but some Angular material components make use of it.
67 let keyCode: number;
68 let emitKeyPressAndInput = true;
69
70 switch (key) {
71 case 'Backspace':
72 nextString =
73 prevString.slice(0, startingCursorIndex - 1) +
74 prevString.slice(startingCursorIndex);
75 nextCursorIndex = startingCursorIndex - 1;
76 keyCode = 0x08;
77 break;
78 case 'Space':
79 nextString =
80 prevString.slice(0, startingCursorIndex) +
81 ' ' +
82 prevString.slice(startingCursorIndex);
83 nextCursorIndex = startingCursorIndex + 1;
84 keyCode = 0x20;
85 break;
86 case 'ArrowLeft':
87 nextString = prevString;
88 nextCursorIndex = startingCursorIndex - 1;
89 keyCode = 0x25;
90 emitKeyPressAndInput = false;
91 break;
92 case 'ArrowUp':
93 nextString = prevString;
94 nextCursorIndex = startingCursorIndex - 1;
95 keyCode = 0x26;
96 emitKeyPressAndInput = false;
97 break;
98 case 'ArrowRight':
99 nextString = prevString;
100 nextCursorIndex = startingCursorIndex + 1;
101 keyCode = 0x27;
102 emitKeyPressAndInput = false;
103 break;
104 case 'Tab':
105 nextString = prevString;
106 nextCursorIndex = startingCursorIndex;
107 keyCode = 0x09;
108 break;

Callers 5

changeInputValueFunction · 0.90
sendKeysFunction · 0.85

Calls 1

dispatchEventMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…