Skip to content

Commit

Permalink
Fix clipboard issue on Windows
Browse files Browse the repository at this point in the history
Signed-off-by: Dominik Jelinek <[email protected]>
  • Loading branch information
djelinek committed Jun 8, 2023
1 parent a4838d8 commit 6d7434f
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 11 deletions.
10 changes: 8 additions & 2 deletions page-objects/src/components/bottomBar/AbstractViews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,20 @@ export abstract class TextView extends ChannelView {
* @returns Promise resolving to the view's text
*/
async getText(): Promise<string> {
const originalClipboard = clipboard.readSync();
let originalClipboard = '';
try {
originalClipboard = clipboard.readSync();
} catch (error) {
}
let textarea = await this.findElement(ChannelView.locators.BottomBarViews.textArea);
await textarea.sendKeys(Key.chord(TextView.ctlKey, 'a'));
await textarea.sendKeys(Key.chord(TextView.ctlKey, 'c'));
const text = clipboard.readSync();
// workaround as we are getting "element click intercepted" during the send keys actions.
// await textarea.click();
clipboard.writeSync(originalClipboard);
if(originalClipboard.length > 0) {
clipboard.writeSync(originalClipboard);
}
return text;
}

Expand Down
10 changes: 8 additions & 2 deletions page-objects/src/components/bottomBar/Views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,11 @@ export class TerminalView extends ChannelView {
* @returns Promise resolving to all terminal text
*/
async getText(): Promise<string> {
const originalClipboard = clipboard.readSync();
let originalClipboard = '';
try {
originalClipboard = clipboard.readSync();
} catch (error) {
}
const workbench = new Workbench();
await workbench.executeCommand('terminal select all');
await workbench.getDriver().sleep(500);
Expand All @@ -138,7 +142,9 @@ export class TerminalView extends ChannelView {
await workbench.getDriver().sleep(500);
}
const text = clipboard.readSync();
clipboard.writeSync(originalClipboard);
if(originalClipboard.length > 0) {
clipboard.writeSync(originalClipboard);
}
return text;
}

Expand Down
30 changes: 24 additions & 6 deletions page-objects/src/components/editor/TextEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,19 @@ export class TextEditor extends Editor {
* @returns Promise resolving to editor text
*/
async getText(): Promise<string> {
const originalClipboard = clipboard.readSync();
let originalClipboard = '';
try {
originalClipboard = clipboard.readSync();
} catch (error) {
}
const inputarea = await this.findElement(TextEditor.locators.Editor.inputArea);
await inputarea.sendKeys(Key.chord(TextEditor.ctlKey, 'a'), Key.chord(TextEditor.ctlKey, 'c'));
await new Promise(res => setTimeout(res, 500));
const text = clipboard.readSync();
await inputarea.sendKeys(Key.UP);
clipboard.writeSync(originalClipboard);
if(originalClipboard.length > 0) {
clipboard.writeSync(originalClipboard);
}
return text;
}

Expand All @@ -117,11 +123,17 @@ export class TextEditor extends Editor {
* @returns Promise resolving once the new text is copied over
*/
async setText(text: string, formatText: boolean = false): Promise<void> {
const originalClipboard = clipboard.readSync();
let originalClipboard = '';
try {
originalClipboard = clipboard.readSync();
} catch (error) {
}
const inputarea = await this.findElement(TextEditor.locators.Editor.inputArea);
clipboard.writeSync(text);
await inputarea.sendKeys(Key.chord(TextEditor.ctlKey, 'a'), Key.chord(TextEditor.ctlKey, 'v'));
clipboard.writeSync(originalClipboard);
if(originalClipboard.length > 0) {
clipboard.writeSync(originalClipboard);
}
if (formatText) {
await this.formatDocument();
}
Expand Down Expand Up @@ -225,7 +237,11 @@ export class TextEditor extends Editor {
* Get the text that is currently selected as string
*/
async getSelectedText(): Promise<string> {
const originalClipboard = clipboard.readSync();
let originalClipboard = '';
try {
originalClipboard = clipboard.readSync();
} catch (error) {
}
if(process.platform !== 'darwin') {
const selection = await this.getSelection();
if (!selection) {
Expand All @@ -241,7 +257,9 @@ export class TextEditor extends Editor {
}
await new Promise(res => setTimeout(res, 500));
const text = clipboard.readSync();
clipboard.writeSync(originalClipboard);
if(originalClipboard.length > 0) {
clipboard.writeSync(originalClipboard);
}
return text;
}

Expand Down
2 changes: 1 addition & 1 deletion test/test-project/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
"lint": "eslint src --ext .ts",
"watch": "tsc -watch -p ./",
"cb-init": "echo hello_ExTester | clipboard",
"ui-test": "npm run cb-init && extest setup-and-run './out/src/test/cli/order-3-test.js' './out/src/test/cli/order-2-test.js' './out/src/test/cli/order-1-test.js' './out/src/test/**/*-test.js' './out/src/test/system/clipboard.test.js' -u -i -r . -e ./test-extensions"
"ui-test": "extest setup-and-run './out/src/test/cli/order-3-test.js' './out/src/test/cli/order-2-test.js' './out/src/test/cli/order-1-test.js' './out/src/test/**/*-test.js' -u -i -r . -e ./test-extensions"
},
"devDependencies": {
"@types/chai": "^4.3.4",
Expand Down

0 comments on commit 6d7434f

Please sign in to comment.