Skip to content

Support controlling whether edits are pre-ticked in WorkspaceEdits with needsConfirmation=true #207578

Description

@DanTup

It's sometimes useful to force the user to review a preview of refactor changes before applying. This can be done with needsConfirmation:

const edit = new vscode.WorkspaceEdit();
const doc = await vscode.workspace.openTextDocument({ language: "text", content: "" });
edit.insert(doc.uri, new vscode.Position(0, 0), "This is inserted text", {
	label: "Insert imports",
	needsConfirmation: true, // Show preview, but also requires ticking
});
edit.insert(doc.uri, new vscode.Position(0, 0), "This is inserted text", {
	label: "Update code",
	needsConfirmation: true, // Show preview, but also requires ticking
});
vscode.workspace.applyEdit(edit);

image

However, the user needs to tick each change (at least the unique labels, which have a "Toggle Change" option on the context menu) which can be a pain if the edit is making a lot of changes that are grouped (for example fixing lint failures across a workspace, with each lint being a group).

It would be a much nicer experience if we could trigger the preview, but with everything ticked by default. In many cases we know the user is likely to apply all of the changes, but we still want to trigger a preview to be shown.

Activity

  1. jasonwang82 commented on Apr 7, 2024

    @jasonwang82

    It is a good suggestion, and we have the same thoughts of feedback. Or, is it possible vscode can add a button by default, saying select all/unselect all

  2. added
    feature-request
    ux
    on Apr 8, 2024
  3. vscodenpa commented on Apr 8, 2024

    @vscodenpa

    This feature request is now a candidate for our backlog. The community has 60 days to upvote the issue. If it receives 20 upvotes we will move it to our backlog. If not, we will close it. To learn more about how we handle feature requests, please see our documentation.

    Happy Coding!

  4. DanTup commented on Apr 10, 2024

    @DanTup
    ContributorAuthor

    Johannes Rieken (@jrieken) would you accept a PR to add something here?

    For example an additional flag needsPreview that triggers the preview without being unticked?

    Refactor previews that don't use commands are all ticked by default, so not being able to do it here leads to inconsistent refactors depending on whether they are CodeActions or triggered from commands.

  5. vscodenpa commented on Apr 11, 2024

    @vscodenpa

    🙂 This feature request received a sufficient number of community upvotes and we moved it to our backlog. To learn more about how we handle feature requests, please see our documentation.

    Happy Coding!

  6. DanTup commented on Apr 11, 2024

    @DanTup
    ContributorAuthor

    Started on a PR at #210175, feedback appreciated!

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

    feature-requestuxworkspace-edit

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions