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

Added spacing when toggling block comments in JavaScript #30656

Closed
michaelgmcd opened this issue Jul 14, 2017 · 7 comments
Closed

Added spacing when toggling block comments in JavaScript #30656

michaelgmcd opened this issue Jul 14, 2017 · 7 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug verified Verification succeeded
Milestone

Comments

@michaelgmcd
Copy link

When toggling and untoggling block comments in JavaScript (I haven't tested other languages), extra spaces are added to the beginning and end of the block each time.

This did not happen in the previous version of VSCode.

  • VSCode Version: 1.14.1
  • OS Version: MacOS Sierra

Steps to Reproduce:

  1. Toggle a block comment in a section of JavaScript.
  2. Untoggle it and notice the added spacing.

Reproduces without extensions: Yes

@cleidigh
Copy link
Contributor

cleidigh commented Jul 14, 2017

@mjbvz
I'm experiencing this with CSS files as well.

If no one is working on this already I will investigate and do a PR.

@mjbvz mjbvz removed the javascript JavaScript support issues label Jul 14, 2017
@mjbvz mjbvz assigned alexdima and unassigned mjbvz Jul 14, 2017
@mjbvz mjbvz added the editor label Jul 14, 2017
@mjbvz
Copy link
Collaborator

mjbvz commented Jul 14, 2017

Thanks. Confirmed that this is not js specific. The same issue also shows up in c files and other language types

@cleidigh
Copy link
Contributor

@mjbvz
@alexandrudima
Does "Thanks" mean and go ahead and do a PR in this? ;-)

I think this was introduced June eighth with
97105c2
adding spaces to block comments, the reverse operation did not take the spaces into account.
Will fix with go-ahead...

public static _createAddBlockCommentOperations(r: Range, startToken: string, endToken: string): editorCommon.IIdentifiedSingleEditOperation[] {
	var res: editorCommon.IIdentifiedSingleEditOperation[] = [];

	if (!Range.isEmpty(r)) {
		// Insert block comment start
		res.push(EditOperation.insert(new Position(r.startLineNumber, r.startColumn), startToken + ' '));

		// Insert block comment end
		res.push(EditOperation.insert(new Position(r.endLineNumber, r.endColumn), ' ' + endToken));
	} else {
		// Insert both continuously
		res.push(EditOperation.replace(new Range(
			r.startLineNumber, r.startColumn,
			r.endLineNumber, r.endColumn
		), startToken + '  ' + endToken));
	}

	return res;
}

@mjbvz
Copy link
Collaborator

mjbvz commented Jul 14, 2017

@cleidigh Sure. @rebornix should be able to help with the PR or answer questions about the code

@cleidigh
Copy link
Contributor

cleidigh commented Jul 14, 2017

@rebornix
One potential fix is very simple, add one to the delete ranges for removing the comments.

public static _createRemoveBlockCommentOperations(r: Range, startToken: string, endToken: string): editorCommon.IIdentifiedSingleEditOperation[] {
var res: editorCommon.IIdentifiedSingleEditOperation[] = [];

	if (!Range.isEmpty(r)) {
		// Remove block comment start
		
		res.push(EditOperation.delete(new Range(
			r.startLineNumber, r.startColumn - startToken.length,
			r.startLineNumber, r.startColumn + 1
		)));

		// Remove block comment end
		res.push(EditOperation.delete(new Range(
			r.endLineNumber, r.endColumn - 1,
			r.endLineNumber, r.endColumn + endToken.length
		)));
	} else {

Personally I don't think it's a good idea to do these mathematics, you would need fix ups
everywhere you are doing the calculation on token length. The commit adding the spaces
is essentially hardcoded, in other words the Space is not part of the actual token.
This means everywhere you use the length of the token you have to do the manual adjustment,
that doesn't seem like a good idea.

Shouldn't the space be part of the tokens? Let me know how you want to handle it and I will do a PR
Cheers

@cleidigh
Copy link
Contributor

@rebornix
Well I see the single-line comment adds the space separately and adjusts the math wherever it needs it.
I'm guessing this is the way you'd prefer to do it.

@cleidigh
Copy link
Contributor

Fixed with PR #30818
All Languages

@cleidigh cleidigh marked this as a duplicate of #30729 Jul 16, 2017
@rebornix rebornix added this to the July 2017 milestone Jul 18, 2017
@rebornix rebornix added the bug Issue identified by VS Code Team member as probable bug label Jul 18, 2017
@roblourens roblourens added the verified Verification succeeded label Aug 3, 2017
@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

6 participants