Move return earlier

This commit is contained in:
zeertzjq
2026-05-11 14:11:28 +08:00
parent b0f5bc2d28
commit e0add7fe4b
+25 -26
View File
@@ -471,34 +471,33 @@ export class KittyKeyboard {
return result; return result;
} }
// Special handling for Enter/Tab/Backspace.
const specialKey = keyCode === 13 || keyCode === 9 || keyCode === 127;
// Per spec, Enter/Tab/Backspace will not have release events unless "Report all keys as escape
// codes" is also set.
if (specialKey && eventType === KittyKeyboardEventType.RELEASE && !(flags & KittyKeyboardFlags.REPORT_ALL_KEYS_AS_ESCAPE_CODES)) {
return result;
}
const isFunc = this._functionalKeyCodes[ev.key] !== undefined || this._getNumpadKeyCode(ev) !== undefined; const isFunc = this._functionalKeyCodes[ev.key] !== undefined || this._getNumpadKeyCode(ev) !== undefined;
let useCsiU = false; const useCsiU = !!(
flags & KittyKeyboardFlags.REPORT_ALL_KEYS_AS_ESCAPE_CODES ||
if (flags & KittyKeyboardFlags.REPORT_ALL_KEYS_AS_ESCAPE_CODES) { (reportEventTypes && eventType === KittyKeyboardEventType.RELEASE) ||
useCsiU = true; (flags & KittyKeyboardFlags.DISAMBIGUATE_ESCAPE_CODES &&
} else if (reportEventTypes && eventType === KittyKeyboardEventType.RELEASE) { (
// Per spec, Enter/Tab/Backspace will not have release events unless "Report all keys as // Per spec, Enter/Tab/Backspace "still generate the same bytes as in legacy mode" and
// escape codes" (which is handled by the branch above) is also set. // consider space to be a text-generating key, so these skip the isFunc fast-path and only
if (keyCode === 13 || keyCode === 9 || keyCode === 127) { // get CSI u when modifiers are present (handled below).
return result; (isFunc && !specialKey) ||
} (
useCsiU = true; (modifiers > 0 && ev.key.length !== 1) ||
} else if (flags & KittyKeyboardFlags.DISAMBIGUATE_ESCAPE_CODES) { modifiers - 1 > KittyKeyboardModifiers.SHIFT
// Per spec, Enter/Tab/Backspace "still generate the same bytes as in legacy )
// mode" and consider space to be a text-generating key, so these skip the isFunc fast-path )
// and only get CSI u when modifiers are present (handled below). )
const isDisambiguateLegacy = keyCode === 13 || keyCode === 9 || keyCode === 127; );
if (isFunc && !isDisambiguateLegacy) {
useCsiU = true;
} else if (modifiers > 0) {
if (ev.shiftKey && !ev.ctrlKey && !ev.altKey && !ev.metaKey && ev.key.length === 1) {
useCsiU = false;
} else {
useCsiU = true;
}
}
}
if (useCsiU) { if (useCsiU) {
result.key = this._buildCsiUSequence(ev, keyCode, modifiers, eventType, flags, isFunc, isMod); result.key = this._buildCsiUSequence(ev, keyCode, modifiers, eventType, flags, isFunc, isMod);