You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 3, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Mar 3, 2023. It is now read-only.
Enhance Atom's Mac Services support to include text services (editor not NSText) #10213
Atom's Service support includes non text services. However, as the Atom text editor is a custom component not identified as text, the text services aren't show.
Thank you for your help. Don't hesitate to ask for further details if necessary.
Reacted by Vincent Esche, Zeping Lee, Stephen Howells, Daniel Bayley, Watts Martin, jyin, Ben Brooks, Ricardo Lima, Chris Dzombak, Chris J. Shull and 5 more
To interoperate with OS X System Services, objects in the responder chain need to implement three methods:
The system calls -validRequestorForSendType:returnType: to check whether services of a certain type (services that receive sendType and return returnType) are applicable in the current state of the application.
When a service (that receives data) is activated, the system calls -writeSelectionToPasteboard:types: to let the application write input data to the service.
When a service (that returns data) is finished, the system calls -readSelectionFromPasteboard: to let the application read result data from the service.
Chromium
The chromium infrastructure code implements all of these methods in the classes RenderWidgetHostViewCocoa and BridgedContentView:
For validRequestorForSendType:returnType:, both return self if:
Both types are be either text or null. This filters services that produce or consume non-textual data.
If the services consumes text, the view must have a selection:
- RenderWidgetHostViewCocoa checks !renderWidgetHostView_->selected_text().empty()
- BridgedContentView checks [self selectedRange].length > 0
If the services produces text, the view must be textual:
- RenderWidgetHostViewCocoa checks renderWidgetHostView_->text_input_type_ != ui::TEXT_INPUT_TYPE_NONE
- BridgedContentView checks textInputClient_
For -writeSelectionToPasteboard:types:, both write the current selection:
For -readSelectionFromPasteboard:, both insert the read text using -insertText:.
Atom
Cursory inspection (using F-Script) reveals that the root view of Atom is a RenderWidgetHostViewCocoa which contains everything except the titlebar, so let's focus on that.
In order for Atom text editors to interoperate with system services, we need to inform that view of our editor's selection. The appropriate method to call for this seems to be RenderWidgetHostViewMac::SelectionChanged, which updates the selection stored in the contained renderWidgetHostView_ property.
It seems that we'll need a way to call this method from Atom, but not having grasped how all the parts of Atom/Electron fit together I'm not sure where to start making this connection.
Electron already includes calls to the render widget host view in electron/atom/browser/api/atom_api_web_contents.cc, although I'm not sure whether that's relevant here.
Multiple Selections
As an additional issue, Atom text editors may contain multiple selections. The system services architecture does not seem to accommodate this: The methods for exchanging data with services are called by the operating system and allow transmitting a single piece of data (per distinct pasteboard key).
There is a way to invoke services programmatically using NSPerformService, but calling this function requires the name of the service, which none of the other methods reveal, so repeating a given service invocation for each selection seems not to be possible.
It seems that this leaves us with the choice of
either only ever invoking services on the first selections
or disabling services altogether when there are multiple selections.
The lack of this means text services that all OS X users expect, like the built-in dictionary's Look Up "x", the built-in text-to-speech's Start Speaking/Stop Speaking, and various other things like Add to Notes, are unavailable.
This issue has been automatically marked as stale because it has not had recent activity. Because the Atom team treats their issues as their backlog, stale issues are closed. If you would like this issue to remain open:
Verify that you can still reproduce the issue in the latest version of Atom
Comment that the issue is still reproducible and include:
What version of Atom you reproduced the issue on
What OS and version you reproduced the issue on
What steps you followed to reproduce the issue
Issues that are labeled as triaged will not be automatically marked as stale.
From what we've seen other than Services, most macOS tools that manipulate text within a program, such as TextExpander, interoperate with Atom's TextEditor without problems. Because of these workarounds, adding support for macOS Services is not something that the Atom team is going to take on.
We would be willing to review a very professionally written pull request. But because of the complexity of integrating with Atom at such a low level, it would need to be very detailed in its design, implementation, and testing, so that we can verify it would not be disruptive to the experience of other users. Please keep that in mind if anyone decides to tackle this task.
I'm going to close this issue and mark it with the help-wanted label so that others may find it if they're interested.
Activity
linickx commentedon Feb 17, 2016
jayvarner commentedon Mar 10, 2016
mkhl commentedon Mar 17, 2016
mkhl commentedon Mar 21, 2016
To interoperate with OS X System Services, objects in the responder chain need to implement three methods:
-validRequestorForSendType:returnType:to check whether services of a certain type (services that receivesendTypeand returnreturnType) are applicable in the current state of the application.-writeSelectionToPasteboard:types:to let the application write input data to the service.-readSelectionFromPasteboard:to let the application read result data from the service.Chromium
The chromium infrastructure code implements all of these methods in the classes
RenderWidgetHostViewCocoaandBridgedContentView:validRequestorForSendType:returnType:, both returnselfif:-
RenderWidgetHostViewCocoachecks!renderWidgetHostView_->selected_text().empty()-
BridgedContentViewchecks[self selectedRange].length > 0-
RenderWidgetHostViewCocoachecksrenderWidgetHostView_->text_input_type_ != ui::TEXT_INPUT_TYPE_NONE-
BridgedContentViewcheckstextInputClient_-writeSelectionToPasteboard:types:, both write the current selection:RenderWidgetHostViewCocoausesrenderWidgetHostView_->selected_text()BridgedContentViewusestextInputClient_->GetTextFromRange(selectionRange, &text)-readSelectionFromPasteboard:, both insert the read text using-insertText:.Atom
Cursory inspection (using F-Script) reveals that the root view of Atom is a
RenderWidgetHostViewCocoawhich contains everything except the titlebar, so let's focus on that.In order for Atom text editors to interoperate with system services, we need to inform that view of our editor's selection. The appropriate method to call for this seems to be
RenderWidgetHostViewMac::SelectionChanged, which updates the selection stored in the containedrenderWidgetHostView_property.It seems that we'll need a way to call this method from Atom, but not having grasped how all the parts of Atom/Electron fit together I'm not sure where to start making this connection.
Electron already includes calls to the render widget host view in
electron/atom/browser/api/atom_api_web_contents.cc, although I'm not sure whether that's relevant here.Multiple Selections
As an additional issue, Atom text editors may contain multiple selections. The system services architecture does not seem to accommodate this: The methods for exchanging data with services are called by the operating system and allow transmitting a single piece of data (per distinct pasteboard key).
There is a way to invoke services programmatically using
NSPerformService, but calling this function requires the name of the service, which none of the other methods reveal, so repeating a given service invocation for each selection seems not to be possible.It seems that this leaves us with the choice of
ToniWonKanobi commentedon Mar 31, 2016
@mkhl, in response to this:
... I would vote for the former (and I think most people would agree given the choice).
Most OS X Services users are okay with modifying only one text selection at at time.
If we could just do that, all would be well.
alexchandel commentedon May 6, 2016
The lack of this means text services that all OS X users expect, like the built-in dictionary's
Look Up "x", the built-in text-to-speech'sStart Speaking/Stop Speaking, and various other things likeAdd to Notes, are unavailable.stale commentedon Apr 5, 2018
magp commentedon Apr 6, 2018
This issue is still current in Atom 1.25.1 on a Mac OSX 10.13.3
Steps to reproduce:
When doing this you will see that the services for text are not available.
stale commentedon Apr 6, 2019
Thanks for your contribution!
This issue has been automatically marked as stale because it has not had recent activity. Because the Atom team treats their issues as their backlog, stale issues are closed. If you would like this issue to remain open:
Issues that are labeled as triaged will not be automatically marked as stale.
chrisjshull commentedon Apr 22, 2019
This issue is still current in Atom 1.36.0 on a macOS 10.14.4.
please reopen
lee-dohm commentedon Apr 23, 2019
Thanks very much.
From what we've seen other than Services, most macOS tools that manipulate text within a program, such as TextExpander, interoperate with Atom's
TextEditorwithout problems. Because of these workarounds, adding support for macOS Services is not something that the Atom team is going to take on.We would be willing to review a very professionally written pull request. But because of the complexity of integrating with Atom at such a low level, it would need to be very detailed in its design, implementation, and testing, so that we can verify it would not be disruptive to the experience of other users. Please keep that in mind if anyone decides to tackle this task.
I'm going to close this issue and mark it with the
help-wantedlabel so that others may find it if they're interested.rpkrajewski commentedon Apr 23, 2019