-
Notifications
You must be signed in to change notification settings - Fork 908
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
Conversation
Pull Request Test Coverage Report for Build 384365367
💛 - 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> { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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 } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This key binding is already used for RunCurrentQueryWithActualPlan https://github.com/microsoft/azuredatastudio/blob/main/src%2Fsql%2Fworkbench%2Fcontrib%2Fquery%2Fbrowser%2Fquery.contribution.ts#L132
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this 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> { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- You shouldn't be returning null - we use undefined in nearly all cases
- The return type is void so you shouldn't be returning anything at all
- Since this is an async function you can just remove this line and it'll work as expected
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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?
There was a problem hiding this 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
src/sql/workbench/contrib/query/browser/keyboardQueryActions.ts
Outdated
Show resolved
Hide resolved
src/vs/workbench/services/clipboard/electron-sandbox/clipboardService.ts
Outdated
Show resolved
Hide resolved
src/vs/workbench/test/electron-browser/workbenchTestServices.ts
Outdated
Show resolved
Hide resolved
* 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>
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:
Copied text in outlook:
Copied text in notepad: