-
Notifications
You must be signed in to change notification settings - Fork 30k
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
Add support for macOS globalFindClipboard #11233 #28896 #35956
Add support for macOS globalFindClipboard #11233 #28896 #35956
Conversation
I would like to know whether dependency injection into CommonFindController is the right thing to do. |
@alexandrudima I would love some help with this. |
@bpasero I would love to finish this PR and submit the PR :) In issue 11233 in reply to one of your comments I had a question. I wanted to know what you meant by "the adoption should take place in vs/editor.." and "you need to provide a shim for this method (or no-op implementation)." in your previous comment Let me know if I am missing anything. Let me know if I'm correct in my approach. Thank You |
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 the
IClipboardService
optional - write more often to the global find clipboard. I'm not sure if that's expected on OSX, but I'd write to it, everytime the user changes the find string, not just when starting to find.
- I'm not sure when it is the best time to read from the global find clipboard? The
NextMatchFindAction
seems as a random place to read from it. - write some tests to express what the desired behaviour is.
@@ -119,7 +120,8 @@ export abstract class CommonCodeEditor extends Disposable implements editorCommo | |||
domElement: IContextKeyServiceTarget, | |||
options: editorOptions.IEditorOptions, | |||
instantiationService: IInstantiationService, | |||
contextKeyService: IContextKeyService | |||
contextKeyService: IContextKeyService, | |||
clipboardService: IClipboardService |
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.
There's no need for the IClipboardService
in this class, so it should be removed from here.
@@ -27,9 +28,10 @@ export class FindController extends CommonFindController implements IFindControl | |||
@IContextKeyService contextKeyService: IContextKeyService, | |||
@IKeybindingService keybindingService: IKeybindingService, | |||
@IThemeService themeService: IThemeService, | |||
@IStorageService storageService: IStorageService | |||
@IStorageService storageService: IStorageService, | |||
@IClipboardService clipBoardService: IClipboardService |
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 recommend using @optional(IClipboardService) clipBoardService: IClipboardService
like it is used here. This will help with the standalone editor (the monaco editor).
optional
is defined in vs/platform/instantiation/common/instantiation
Then, the code should assume that this service could be undefined/null
nitpick: perhaps name it
clipboardService
instead ofIClipboardService
to keep in spirit with the service name.
@@ -308,6 +311,14 @@ export class CommonFindController extends Disposable implements editorCommon.IEd | |||
} | |||
return true; | |||
} | |||
|
|||
public showGlobalBufferTerm(): string { | |||
return this._clipboardService.readFindText(); |
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.
Once optional
is adopted, some null/undefined checks should be performed here
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'm also not sure why this method is called show...
, it looks like a getter/reader
} | ||
|
||
public setGlobalBufferTerm(text: string) { | ||
this._clipboardService.writeFindText(text); |
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.
Once optional
is adopted, some null/undefined checks should be performed here
@@ -378,7 +391,21 @@ export class NextMatchFindAction extends MatchFindAction { | |||
} | |||
|
|||
protected _run(controller: CommonFindController): boolean { |
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.
Here we are always using the search string found in the global search clipboard, but we write to the global search clipboard only in the StartSearchAction
. Perhaps the controller should write to the global search clipboard on each and every findState
change ? i.e. anytime the user types in the find input ?
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.
Everytime time the user types in the find input, I am writing to the global buffer . Also, everytime the user changes the global buffer using some other app and returns back to vscode, if the find box is open the find search string changes based on the global buffer
7f58d1c
to
2f267ee
Compare
TODO: Add test and restrict it to OSX
2f267ee
to
41a422c
Compare
Thanks for the review. I will look into it and make the required changes. Could you let me know which version of node and npm is preferred. |
Here are the tooling requirements: https://github.com/Microsoft/vscode/wiki/How-to-Contribute#installing-prerequisites |
Out of curiosity I built and ran this branch but it didn't seem to interact with the find clipboard yet when I tried it. Is that supposed to work already or is more work needed? |
@liyanage It should be working now. Previously, I had rebased my branch which included few tests to pass before building an executable and probably thats why the feature didn't work. Give the latest one a shot and let me know. |
Resolved review comments. Let me know your thoughts on the same |
I pulled the latest and tried again, and it works great! One small detail that is unexpected and that I would change is that hitting Cmd-E in VSC with a text selection does not just populate the find clipboard, it also enters find mode and brings up the small find overlay in the upper right corner. That is not how Cmd-E usually works, in all other Mac apps it just silently populates the find clipboard but does not perform any other action or visibly change the UI. Thanks for your work on this, can't wait to see it in a build! |
@liyanage Thanks a lot for trying it out. In VScode if you select something and press Cmd F it opens the find overlay in upper right corner with the selected text in the find box. Since, Cmd E is a just an extension of Cmd F it behaves similar to Cmd F |
@alexandrudima Let me know if more changes need to be done. Thanks |
Giving to @rebornix as he is back. I've resolved the conflicts my refactorings have caused. |
@melvin0008 the code looks good to me, thanks for your contribution! Before merging this PR, there are just two little things to do
Speaking of the second one, we may need to think about how often this feature surprises users who are not familiar with this mac feature, and then decide whether we need a setting from the very beginning. |
@rebornix Thanks for the feedback. I feel it shouldn't surprise Mac users since this behavior is supported in most of the tools. Chrome, Sublime Text, Safari, Notes, Firefox are few tools I know which support this feature. |
Where should I add the summary? |
@melvin0008 you can send PR against vscode-docs vnext branch and add this to Notable Changes, write it like |
Add support for macOS's NSFindPboard, which is a global shared find buffer. This allows one to put text into the find buffer from other native apps like Chrome, TextEdit, Safari, Sublime, etc. and then switch to other Cocoa apps and use cmd-g to find next matching text. Pull request for this change is microsoft/vscode#35956
@rebornix Added the PR against vscode-docs vnext branch like suggested. There was a difference in the format though, it was #issue-number :short-description. Thanks let me know if there is anything else to be done |
@melvin0008 it looks great! Thanks for your contribution ;) |
:) My pleasure. Always fun contributing to the products I use extensively. Thanks for vscode :) |
Add support for macOS's NSFindPboard, which is a global shared find buffer. This allows one to put text into the find buffer from other native apps like Chrome, TextEdit, Safari, Sublime, etc. and then switch to other Cocoa apps and use cmd-g to find next matching text. Pull request for this change is microsoft/vscode#35956
so happy for this feature!! found a couple of implementation bugs. want me to open new issues @melvin0008 @rebornix ? |
Sure. |
I'm also very happy for this feature. Other Mac apps that support it also include BBEdit, TextEdit, Mail, and Preview. |
I use vscode on windows, and have been a bit frustrated that when I have editors open in multiple panes, all of the panes have their own find state - so if I start searching for something, and want to continue my search in the next pane, I have to copy the search string, switch to the other pane, start a new search and then paste the string. By any chance would it be possible to implement a 'global find clipboard' for the windows version not to share the find string across the whole OS, but just to make it possible for the different panes to share a common find state? |
It's real nice that a version of this is in there, but the behavior is still inconsistent with other programs. In short: shifting the focus to the find menu is atypical. On this end at least, the behavior causes problems with the following pattern:
Steps 3 and 4 break when the focus shifts to the find pallet. I get tripped up on this regularly. I'm not sure how common the above pattern is among other users, but I use it a frequently, especially when bashing out prototypes—mostly in cases where VSCode does not recognize all instances of a symbol, or if I'm not certain it'll find them all and would like to quickly step through each replacement to make sure, or the selected text occurs in parts of other related symbol names and I'd also like to update those, e.g. my_var / my_var_previous, or when the symbol name occurs across multiple languages in a project or document (e.g. php/html/css/js...) |
I agree, the find clipboard behavior is still not comparable to a native app. As described by @IanBellomy it's because of the find UI appearing when it should not. I should be able to Hit Cmd-E in VC or another app, switch to VC and hit Cmd-G and the selection should move to the next hit. At no point in this interaction should the find UI ever appear. |
Another way to put it is this: selecting text then pressing command+e is a way to specify a search token, and so is editing some text in a find-input. Jumping to a find input to specify a search token after specifying the search token may be redundant in many situations. |
Is this supposed to work? I'm using cmd-e in various apps and nothing seems to affect VSCode. Do I have to enable a setting? |
Update: you have to turn on Editor > Find: Global Find Clipboard and Search: Global Find Clipboard to get this feature to work. It's not perfect, but it works with my muscle memory at least. The only bug I'd file is that if you cmd-E in one editor pane, the search string in another editor pane is not immediately updated, even though if you cmd-G in that other editor pane it does immediately use the correct string (not the displayed one) |
Fixes #11233 #28896 and #3431 by adding support for macOS globalFindClipboard
Summary of Changes:
I added API to IClipboardService.
Used dependency injection to inject the service in CommonFindController and wrote helper functions to use the apis. Should this be on the Controller or the editor object?
Then I used these helper functions in StartFindAction and NextMatchFindAction