MCPcopy
hub / github.com/VSCodeVim/Vim / sendKey

Method sendKey

src/configuration/remapper.ts:95–465  ·  view source on GitHub ↗
(keys: string[], modeHandler: ModeHandler)

Source from the content-addressed store, hash-verified

93 }
94
95 public async sendKey(keys: string[], modeHandler: ModeHandler): Promise<boolean> {
96 const { vimState, remapState } = modeHandler;
97
98 this._isPotentialRemap = false;
99 const allowPotentialRemapOnFirstKey = vimState.recordedState.allowPotentialRemapOnFirstKey;
100 let remainingKeys: string[] = [];
101
102 /**
103 * Means that the timeout finished so we now can't allow the keys to be buffered again
104 * because the user already waited for timeout.
105 */
106 let allowBufferingKeys = true;
107
108 if (!this.remappedModes.includes(vimState.currentModeIncludingPseudoModes)) {
109 return false;
110 }
111
112 const userDefinedRemappings = configuration[this.configKey] as Map<string, IKeyRemapping>;
113
114 if (keys.at(-1) === SpecialKeys.TimeoutFinished) {
115 // Timeout finished. Don't let an ambiguous or potential remap start another timeout again
116 keys = keys.slice(0, keys.length - 1);
117 allowBufferingKeys = false;
118 }
119
120 if (keys.length === 0) {
121 return true;
122 }
123
124 Logger.trace(
125 `trying to find matching remap. keys=${keys}. mode=${
126 Mode[vimState.currentMode]
127 }. keybindings=${this.configKey}.`,
128 );
129
130 let remapping: IKeyRemapping | undefined = this.findMatchingRemap(userDefinedRemappings, keys);
131
132 // Check to see if a remapping could potentially be applied when more keys are received
133 let isPotentialRemap = Remapper.hasPotentialRemap(keys, userDefinedRemappings);
134
135 this._isPotentialRemap =
136 isPotentialRemap && allowBufferingKeys && allowPotentialRemapOnFirstKey;
137
138 /**
139 * Handle a broken potential or ambiguous remap
140 * 1. If this Remapper doesn't have a remapping AND
141 * 2. (It previously had an AmbiguousRemap OR a PotentialRemap) AND
142 * 3. (It doesn't have a potential remap anymore OR timeout finished) AND
143 * 4. keys length is more than 1
144 *
145 * Points 1-3: If we no longer have a remapping but previously had one or a potential one
146 * and there is no longer potential remappings because of another pressed key or because the
147 * timeout has passed we need to handle those situations by resending the keys or handling the
148 * ambiguous remap and resending any remaining keys.
149 * Point 4: if there is only one key there is no point in resending it without allowing remaps
150 * on first key, we can let the remapper go to the end because since either there was no potential
151 * remap anymore or the timeout finished so this means that the next two checks (the 'Buffer keys
152 * and create timeout' and 'Handle remapping and remaining keys') will never be hit, so it reaches

Callers

nothing calls this directly

Calls 14

findMatchingRemapMethod · 0.95
handleRemappingMethod · 0.95
waitFunction · 0.85
traceMethod · 0.80
hasPotentialRemapMethod · 0.80
resetCommandListMethod · 0.80
debugMethod · 0.80
joinMethod · 0.80
RecursiveMappingMethod · 0.80
displayErrorMethod · 0.80
fromVimErrorMethod · 0.80
finishCurrentStepMethod · 0.80

Tested by

no test coverage detected