Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy clipboard command in ADS (html/plain text supported) #13527

Merged
merged 10 commits into from
Nov 26, 2020

Conversation

gupta1
Copy link
Member

@gupta1 gupta1 commented Nov 24, 2020

This PR fixes #
Adds a keyboard command in ADS to copy query and results in plain text as well as in html formatting. It will paste it to target location in the format supported i.e. word supports html, notepad supports plain text only.

UI for discoverability will be added later once we decide where in ADS we should add it.

Tested it for SQL and Kusto query editor. Screenshots of the feature and results are below:

Command:
image

Copied text in outlook:
image

Copied text in notepad:
image

@gupta1 gupta1 requested a review from alanrenmsft November 24, 2020 01:26
@coveralls
Copy link

coveralls commented Nov 24, 2020

Pull Request Test Coverage Report for Build 384365367

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 617 unchanged lines in 9 files lost coverage.
  • Overall coverage increased (+0.01%) to 41.252%

Files with Coverage Reduction New Missed Lines %
extensions/notebook/src/jupyter/serverInstance.ts 4 73.81%
src/sql/workbench/browser/modelComponents/modelStore.ts 12 48.08%
src/sql/workbench/contrib/notebook/browser/htmlMarkdownConverter.ts 12 78.93%
src/sql/workbench/browser/modelComponents/viewBase.ts 27 1.57%
extensions/resource-deployment/src/ui/deployClusterWizard/pages/serviceSettingsPage.ts 30 5.43%
extensions/azurecore/src/azureResource/commands.ts 48 0%
extensions/azurecore/src/azureResource/tree/flatAccountTreeNode.ts 70 0%
src/sql/workbench/api/common/extHostModelView.ts 118 35.61%
extensions/resource-deployment/src/ui/modelViewUtils.ts 296 4.2%
Totals Coverage Status
Change from base Build 380002068: 0.01%
Covered Lines: 21854
Relevant Lines: 48612

💛 - Coveralls

@@ -13,6 +13,10 @@ export class BrowserClipboardService implements IClipboardService {

private readonly mapTextToType = new Map<string, string>(); // unsupported in web (only in-memory)

async write(data: any, type?: string): Promise<void> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see why this is necessary - but regardless make sure you add {{ SQL CARBON EDIT }} to all lines you modify in the vs dir

Copy link
Member Author

@gupta1 gupta1 Nov 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added write method to IClipboardService which supports copying plain text as well as html formatted text https://www.electronjs.org/docs/api/clipboard#clipboardwritedata-type
Currently BrowserClipboardService and NativeClipboardService both implements IClipboardService. For NativeClipboardService, I have implemented the above method whereas for BrowserClipboardService , it throws "Not Implemented" error. Another option is to only add write method in NativeClipboardService but not sure how it will affect ADS web for this command scenario. Let me know what you think would be the best way.

Copy link
Contributor

@Charles-Gagnon Charles-Gagnon Nov 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha - so basically for things that support HTML the clipboard will paste the HTML text otherwise it'll fall back to plain text? What's the behavior for things like Excel, Notepad, Outlook, etc?

@@ -25,6 +25,10 @@ export class BrowserClipboardService implements IClipboardService {
this._notificationService.info(localize('imageCopyingNotSupported', "Copying images is not supported"));
}

write(data: string): Promise<void> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you adding this? Just use writeText

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have the same type as the vs implementation (which should be the new type you add per my suggestion below)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And why isn't it calling vsClipboardService.write?

CopyQueryWithResultsKeyboardAction,
CopyQueryWithResultsKeyboardAction.ID,
CopyQueryWithResultsKeyboardAction.LABEL,
{ primary: KeyMod.CtrlCmd | KeyCode.KEY_M }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please work with PM to define the shortcut key @gupta1

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, changing it to Ctrl+Alt+C for now since Ctrl+Shift+C which is used in Kusto Explorer is already used for something else in ADS. I can change it later if needed once @MsSQLGirl and Raden are back from vacation next week.

Copy link
Contributor

@Charles-Gagnon Charles-Gagnon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure you add the SQL CARBON EDIT too

@@ -13,6 +13,10 @@ export class BrowserClipboardService implements IClipboardService {

private readonly mapTextToType = new Map<string, string>(); // unsupported in web (only in-memory)

async write(data: any, type?: string): Promise<void> {
Copy link
Contributor

@Charles-Gagnon Charles-Gagnon Nov 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha - so basically for things that support HTML the clipboard will paste the HTML text otherwise it'll fall back to plain text? What's the behavior for things like Excel, Notepad, Outlook, etc?


this._clipboardService.write(data);
}
return Promise.resolve(null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. You shouldn't be returning null - we use undefined in nearly all cases
  2. The return type is void so you shouldn't be returning anything at all
  3. Since this is an async function you can just remove this line and it'll work as expected

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the above comment related to Outlook, notepad behavior:
Yes correct. Excel, Outlook supports HTML text, it shows up with all the formatting whereas Notepad doesnt, so its just plain text.

@@ -13,6 +13,10 @@ export class BrowserClipboardService implements IClipboardService {

private readonly mapTextToType = new Map<string, string>(); // unsupported in web (only in-memory)

async write(data: any, type?: string): Promise<void> {
Copy link
Contributor

@Charles-Gagnon Charles-Gagnon Nov 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be any type though - you should create a new type

export type ClipboardData = {
{
  text?: string;
  html?: string;
  rtf?: string;
  bookmark?: string;
}

and use that instead

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, makes sense. I will add it to clipboardService.ts

html: `${escape(queryText).replace(/\r\n|\n|\r/gm, '<br />')}${allResults.html}`
};

this._clipboardService.write(data);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

await

@IQueryModelService protected readonly queryModelService: IQueryModelService,
) {
super(id, label);
this.enabled = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't expect this to be necessary - what happens if you remove it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed it initially but all other methods had it so wasn't sure if its required for some other settings I am not aware of. I can remove it.

@@ -25,6 +25,10 @@ export class BrowserClipboardService implements IClipboardService {
this._notificationService.info(localize('imageCopyingNotSupported', "Copying images is not supported"));
}

write(data: string): Promise<void> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have the same type as the vs implementation (which should be the new type you add per my suggestion below)

@@ -25,6 +25,10 @@ export class BrowserClipboardService implements IClipboardService {
this._notificationService.info(localize('imageCopyingNotSupported', "Copying images is not supported"));
}

write(data: string): Promise<void> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And why isn't it calling vsClipboardService.write?

@gupta1 gupta1 marked this pull request as ready for review November 24, 2020 23:20
@gupta1 gupta1 changed the title Copy clipboard kusto Copy clipboard command in ADS (html/plain text supported) Nov 24, 2020
Copy link
Contributor

@Charles-Gagnon Charles-Gagnon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some cleanup but functionally looks fine

@gupta1 gupta1 merged commit 397354e into main Nov 26, 2020
@gupta1 gupta1 deleted the copy_clipboard_kusto branch November 26, 2020 05:08
kburtram pushed a commit that referenced this pull request Nov 30, 2020
* draft commit

* few changes

* Changes to copy query with results in plain and html formatting

* undo changes

* undo unintended change

* remove comments

* Addressed comments

* Some clean up

Co-authored-by: Monica Gupta <mogupt@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants