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

Add command for Quarto: Set Editor Default #596

Open
DavisVaughan opened this issue Nov 1, 2024 · 9 comments
Open

Add command for Quarto: Set Editor Default #596

DavisVaughan opened this issue Nov 1, 2024 · 9 comments

Comments

@DavisVaughan
Copy link
Collaborator

Right now you can globally tell VS Code / Positron to use the visual editor by default for ALL qmd documents with this setting:

    "workbench.editorAssociations": {
        "*.qmd": "quarto.visualEditor"
    }

This is officially supported as the way for a user to set their global preference. It's the reason we set priority: "option" for our custom editor in package.json

    "customEditors": [
      {
        "viewType": "quarto.visualEditor",
        "displayName": "Quarto Visual Editor",
        "selector": [
          {
            "filenamePattern": "*.{md,qmd}"
          }
        ],
        "priority": "option"
      }
    ],

https://code.visualstudio.com/api/references/contribution-points#contributes.customEditors

Image

i.e. we don't forcibly take over qmds and make them open in visual mode, but a user can use this editor association option to opt in to this global override if they always want visual mode.


This is a super cool feature, but it's super hard to find!

I vote we make an ephemeral command that the user can call as something like Quarto: Set Editor Default who's sole job would be to follow up with a quick pick where the user can select either Source or Visual, and then based on their answer we set this editorAssociation option for them. It's possible we should also ask them if they want it set at a User or Workspace level.


Note that I do not think we should make this a quarto level option. That leaves the door open for the quarto option to get out of sync with the editor association option, like with manual editing of settings you can confusingly end up with this if we did an option:

    "quarto.editorDefault = "source",
    "workbench.editorAssociations": {
        "*.qmd": "quarto.visualEditor"
    }

and that seems bad. So having it as a command that just sets editorAssociations seems like a better way to do this.

@juliasilge
Copy link
Collaborator

This sort of already exists, since the Quarto extension provides the visual editor editor with "priority": "option":

Image

This quick pick pops up if you ever right click on a .qmd to open it and choose "Open With...". I looked a little bit at whether we can hook a command up to get to this spot but don't see it quite yet.

@juliasilge
Copy link
Collaborator

This quick pick comes from doPickEditor() with showDefaultPicker set to true:

https://github.com/posit-dev/positron/blob/8d0c666584e6a17ade85e6e97e7b9cb6df1eba30/src/vs/workbench/services/editor/browser/editorResolverService.ts#L782-L783

It doesn't look to me like any of that is exposed to extensions, for extensions to prompt this.

@DavisVaughan
Copy link
Collaborator Author

DavisVaughan commented Nov 26, 2024

Oh nice yea if you hit "configure default" after Open with... then if you set it to visual editor then i do see this in my settings.json now

    "workbench.editorAssociations": {
        "*.qmd": "quarto.visualEditor"
    }

That's basically what I'm asking for, just as a slightly simplified version that would only show Source and Visual as options, and is more easily discovered through being a quarto command under > Quarto: Set Editor Default in the command palette

It wouldn't have to use exactly the same UI, so we would not need to access that existing quick picker directly. We'd just make our own simple quick picker that only shows Source and Visual as options.

Or we can decide the current approach is good enough, if a bit hidden

@gregmacfarlane
Copy link

I came across this post looking desperately for a way to stop using the visual editor. Every time I open a .qmd file the visual editor re-writes all of my line endings and latex formatting. Still haven't found it yet, because the dropdown that @juliasilge pointed out still takes me to the visual editor no matter which option I pick!

@juliasilge
Copy link
Collaborator

Hmmmm, interesting. @gregmacfarlane can you walk through these steps, in either VS Code or Positron?

  • In the File Explorer, right click on any .qmd file and choose "Open With..."

Image

  • Click on "Configure default editor for '*.qmd'"

Image

  • Choose "Text Editor"

Image

That will set this in your user settings:

"workbench.editorAssociations": {
        "*.qmd": "default"
    }

Alternatively, you can manually set this in your user settings.json.

Does this not work for you?

@gregmacfarlane
Copy link

gregmacfarlane commented Jan 10, 2025

Steps I see:

  1. right-click on .qmd file in quarto file explorer and select Open with...

Image

  1. select Text Editor which is also listed as the default

Image

  1. VS Code opens the visual editor anyways.

Image

I just noted that if I start a new, empty project the behavior seems correct. So there must be some project-level setting interfering with my choices. Now to to find it. I will note that my user settings already have the

    "workbench.editorAssociations": {
        "*.qmd": "default"
    }

My workspace user settings only have an unrelated setting with

{
    "makefile.configureOnOpen": false
}

@juliasilge
Copy link
Collaborator

Apologies if you have already checked these, but can you check:

  • do you have editor: visual in your _quarto.yml for this project or your specific file?
  • does the specific file financial.qmd set any editor options in it?
  • what happens if you make a brand new simple .qmd file in the same project as this file? does it open in source or visual mode?

@gregmacfarlane
Copy link

Turns out the issue was in the editor: visual in the project _quarto.yml file. It's interesting that this overrides all of the other things, but i've got it now.

@juliasilge
Copy link
Collaborator

Yep, there are hierarchical rules such that a document-level setting overrides a project-level setting which overrides a user-level setting. The motivation here is, for example, that you may collaborate with someone on a project and you both will use the same settings on the project, no matter what individual user-level settings you have.

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

No branches or pull requests

3 participants