Skip to content

Commit

Permalink
Merge pull request #1537 from metalice/CNV-32824-paste-long-strings-v…
Browse files Browse the repository at this point in the history
…nc-console

CNV-32824: Paste long string into vnc console
  • Loading branch information
openshift-merge-robot authored Sep 19, 2023
2 parents 4dd49a2 + ab7ec54 commit 38755e8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@ const CloudInitCredentialsContent: FC<CloudInitCredentialsContentProps> = ({ vm
(acc, user) => ({
passwords: (
<>
{acc.passwords} <InlineCodeClipboardCopy clipboardText={user.password} />
{acc.passwords}
<InlineCodeClipboardCopy
clipboardText={user?.password?.concat(String.fromCharCode(13))}
/>
</>
),
usernames: (
<>
{acc.usernames} <InlineCodeClipboardCopy clipboardText={user.name} />
{acc.usernames}
<InlineCodeClipboardCopy clipboardText={user?.name?.concat(String.fromCharCode(13))} />
</>
),
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
import { css } from '@patternfly/react-styles';
import styles from '@patternfly/react-styles/css/components/Consoles/VncConsole';

import { sleep } from '../../utils/utils';
import { ConsoleState, WS, WSS } from '../utils/ConsoleConsts';
import useCopyPasteConsole from '../utils/hooks/useCopyPasteConsole';

Expand Down Expand Up @@ -132,13 +133,19 @@ export const VncConsole: FC<VncConsoleProps> = ({
return;
}
const clipboardText = await navigator?.clipboard?.readText?.();
[...(clipboardText || pasteText.current)].forEach((char) => {
const text = clipboardText || pasteText.current;
const lastItem = text.length - 1;
for (let i = 0; i < text.length; i++) {
const char = text[i];
const shiftRequired = isShiftKeyRequired(char);

await sleep(50);
shiftRequired && this.sendKey(KeyTable.XK_Shift_L, 'ShiftLeft', true);
this.sendKey(char.charCodeAt(0));
shiftRequired && this.sendKey(KeyTable.XK_Shift_L, 'ShiftLeft', false);
});
i === lastItem &&
clipboardText.charCodeAt(lastItem) === 13 &&
this.sendKey(KeyTable.XK_KP_Enter);
}
};
rfbInstnce.viewOnly = viewOnly;
rfbInstnce.scaleViewport = scaleViewport;
Expand Down
2 changes: 2 additions & 0 deletions src/utils/components/Consoles/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ export const clipboardCopyFunc = (
}),
);
};

export const sleep = (ms = 500) => new Promise((resolve) => setTimeout(resolve, ms));

0 comments on commit 38755e8

Please sign in to comment.