Skip to content

Commit

Permalink
Use flags for meta keys to avoid counter going off the rails when peo…
Browse files Browse the repository at this point in the history
…ple release meta keys after focusing away from the IDE panel
  • Loading branch information
kmagiera committed Oct 30, 2024
1 parent ccaafa0 commit 709215d
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions packages/vscode-extension/src/devices/IosSimulatorDevice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,23 +211,26 @@ export class IosSimulatorDevice extends DeviceBase {
]);
}

private pressingMetaKeys = 0; // 0 - not pressing, 1+ - how many meta keys are pressed
private pressingLeftMetaKey = false;
private pressingRightMetaKey = false;

public sendKey(keyCode: number, direction: "Up" | "Down"): void {
// iOS simulator has a buggy behavior when sending cmd+V key combination.
// It sometimes triggers paste action but with a very low success rate.
// Other times it kicks in before the pasteboard is filled with the content
// therefore pasting the previously compied content instead.
// As a temporary workaround, we disable sending cmd+V as key combination
// entirely to prevent this bugge behavior. Users can still paste content
// using the context menu.
// entirely to prevent this buggy behavior. Users can still paste content
// using the context menu method as they'd do on an iOS device.
// This is not an ideal workaround as people may still trigger cmd+v by
// pressing V first and then cmd, but it is good enough to filter out
// the majority of the noisy behavior since typically you press cmd first.
if (keyCode === LEFT_META_HID_CODE || keyCode === RIGHT_META_HID_CODE) {
this.pressingMetaKeys += direction === "Down" ? 1 : -1;
if (keyCode === LEFT_META_HID_CODE) {
this.pressingLeftMetaKey = direction === "Down";
} else if (keyCode === RIGHT_META_HID_CODE) {
this.pressingRightMetaKey = direction === "Down";
}
if (this.pressingMetaKeys > 0 && keyCode === V_KEY_HID_CODE) {
if ((this.pressingLeftMetaKey || this.pressingRightMetaKey) && keyCode === V_KEY_HID_CODE) {
// ignore sending V when meta key is pressed
} else {
this.preview?.sendKey(keyCode, direction);
Expand Down

0 comments on commit 709215d

Please sign in to comment.