Skip to content

Commit

Permalink
Fix error when using "Rewrap At... command" (#324)
Browse files Browse the repository at this point in the history
Unlike the `rewrapCommentCommand` function, `rewrapCommentAtCommand` has
to be async, because it shows the input popup first. So it can't use the
editBuilder passed directly in (this gives the error "Edit is only valid
while callback runs").

So we have to go back to the old way of using the `editor.edit(...)`
function here. Don't think any harm should come from this.
  • Loading branch information
stkb committed Feb 21, 2022
1 parent e19276b commit c32a0d7
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions vscode/src/Extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function rewrapCommentCommand (editor: TextEditor, editBuilder: TextEditorEdit)
let customWrappingColumn = 0;

/** Does a rewrap, but first prompts for a custom wrapping column to use. */
async function rewrapCommentAtCommand (editor: TextEditor, editBuilder: TextEditorEdit)
async function rewrapCommentAtCommand (editor: TextEditor)
{
let columnStr = customWrappingColumn > 0 ?
customWrappingColumn.toString() : undefined
Expand All @@ -41,7 +41,8 @@ async function rewrapCommentAtCommand (editor: TextEditor, editBuilder: TextEdit
if (columnStr === undefined) return // The user pressed cancel

customWrappingColumn = parseInt(columnStr) || 0
doWrap (editor, editBuilder, customWrappingColumn)
// Since this is an async function, we have to use editor.edit
editor.edit (editBuilder => doWrap (editor, editBuilder, customWrappingColumn))
}


Expand Down

0 comments on commit c32a0d7

Please sign in to comment.