How do i change the way visual studio code auto corrects curly braces? - autocomplete

I prefer my curly braces looking like this:
function eg()
{
}
But when I try to format my code, vscode auto corrects to this:
function eg() {
}
Is there any plugins that I can download or setting that I can tweak to change this?

Try :
"javascript.format.placeOpenBraceOnNewLineForFunctions": true;
"javascript.format.placeOpenBraceOnNewLineForControlBlocks": true;
"typescript.format.placeOpenBraceOnNewLineForControlBlocks": true;
"typescript.format.placeOpenBraceOnNewLineForFunctions": true;

Related

VSCode aggressively deletes all code after unconditional return (no-unreachable)

Sometimes I have code like this:
function x() {
func1();
func2();
func3();
}
and when I'm debugging I put a return on the third line if I don't want/care about func2/func3:
function x() {
func1();
return;
func2();
func3();
}
On save, VSCode very rudely deletes func2 and func3!!! Yes I know it is unreachable code, but I am only adding that return there temporarily. A yellow underline would be nice. I can't seem to turn it off. Is there any way to turn it off or am I using it wrong? It seems like a really silly and overzealous feature to me.
Finally fixed the issue.
In settings.json (~/.config/Code/User/settings.json)
I had:
"source.fixAll": true,
changing this to
"source.fixAll.eslint": true,
Stops the editor removing the unreachable code unnecessarily

Folding regions in visual studio code v1.17 not working

I am using visual studio code v1.17 and I am doing development in pure javascript for chrome extension development. Visual studio code v1.17 supports region folding facility for javascript and several other languages.
So, I created one class inside one .js file and write getter setter methods inside it. like
//#region EmailObj
get EmailObj() {
this._EmailObj = localStorage.getItem("CurrentEmail");
try {
this._EmailObj = JSON.parse(this._EmailObj);
}
catch(e) {
this._EmailObj = null;
}
return this._EmailObj;
}
set EmailObj(newValue) {
this._EmailObj = JSON.stringify(newValue);
localStorage.setItem("CurrentEmail", this._EmailObj)
}
remove_EmailObj() {
this._EmailObj = null;
localStorage.removeItem("CurrentEmail");
}
//#endregion EmailObj
Now as per documentation stated at https://code.visualstudio.com/updates/v1_17#_folding-regions. Plus (+) icon should be shown near #region and #endregion sections (so, I can show / hide particular region) but it is not showing there.
So, somebody help me that what I am missing here?
I updated VS code to 1.17.2 and its now working at my side.

Prevent VS Code from changing indentation on Enter

Let's assume I have a JavaScript file with the following content and the cursor placed at the pipe symbol (|):
class ItemCtrl {
getPropertiesByItemId(id) {
return this.fetchItem(id)
.then(item => {
return this.getPropertiesOfItem(item);
});
}|
}
If I now hit enter, the code changes in the following way:
class ItemCtrl {
getPropertiesByItemId(id) {
return this.fetchItem(id)
.then(item => {
return this.getPropertiesOfItem(item);
});
}
|
}
It wrongly aligns the closing curly brace with the return statement, when it should be aligned with the method definition. I know that the formatting inside the function is not the best but I still would rather disable that feature to prevent weird things like that from happening.
I already set editor.autoIndent to false but it still keeps happening. Is there any other way, how I can turn this feature off entirely? (or make it work in a smarter way)
In VS Code 1.17, this bug caused "editor.autoIndent": false to not work
This should be fixed in VS Code 1.18

Advanced indent settings in Visual Studio

I'm using VS2013 and I'd like to change indentation. However, Visual's settings aren't enough for me. I'd like it to auto indent it like this:
int function()
{
int a=1;
while (a)
{
if(a>0)
{
a=0;
return;
}
}
}
Are there any plugins, or anything like this to help me with indentation?

How can I prevent tinyMCE's paste event?

I need to prevent the paste event of tinyMCE if the length of the current content of editor plus the length of the words to be pasted exceed the specified limit. How can I do it? Thank you.
I was wrong. I dont need to prevent or disable paste in tinyMCE to do this. I used their paste plugin and modified the content before it is pasted.
function(pl, o) {
...
if(len > limit) {
o.content = '';
}
}
I think it's better to use the paste_preprocess function.
It's a old question, but others may stumble on this problem.
Here is the solution:
paste_preprocess: function (plugin, args) {
args.content = ''; // modify or do anything with the clipboard data
},
Do it inside, init