Skip to content
This repository was archived by the owner on Mar 3, 2023. It is now read-only.
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

Closed

Description

@magp

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.

Issue raised from conversation at #3204 (comment)

Activity

  1. added
    mac
    on Dec 29, 2015
  2. linickx commented on Feb 17, 2016

    @linickx
  3. jayvarner commented on Mar 10, 2016

    @jayvarner
  4. mkhl commented on Mar 17, 2016

    @mkhl
  5. mkhl commented on Mar 21, 2016

    @mkhl

    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:
    • RenderWidgetHostViewCocoa uses renderWidgetHostView_->selected_text()
    • BridgedContentView uses textInputClient_->GetTextFromRange(selectionRange, &text)
    • 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.
  6. ToniWonKanobi commented on Mar 31, 2016

    @ToniWonKanobi

    @mkhl, in response to this:

    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.

    ... 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.

  7. alexchandel commented on May 6, 2016

    @alexchandel
    Contributor

    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.

  8. stale commented on Apr 5, 2018

    @stale
  9. magp commented on Apr 6, 2018

    @magp
    Author

    This issue is still current in Atom 1.25.1 on a Mac OSX 10.13.3

    Steps to reproduce:

    1. Create a new file
    2. Type text
    3. Select text
    4. Select "Services" in the Atom menu

    When doing this you will see that the services for text are not available.

  10. stale commented on Apr 6, 2019

    @stale

    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:

    1. Verify that you can still reproduce the issue in the latest version of Atom
    2. 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.

  11. chrisjshull commented on Apr 22, 2019

    @chrisjshull
    Contributor

    This issue is still current in Atom 1.36.0 on a macOS 10.14.4.

    please reopen

  12. lee-dohm commented on Apr 23, 2019

    @lee-dohm
    Contributor

    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 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.

  13. rpkrajewski commented on Apr 23, 2019

    @rpkrajewski
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementhelp-wantedmactriaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions