Author Topic: How to prevent this extra space getting added to JSon/Javascript  (Read 1060 times)

spongyryno

  • Community Member
  • Posts: 48
  • Hero Points: 0
How to prevent this extra space getting added to JSon/Javascript
« on: September 08, 2021, 01:57:56 AM »
Whenever I edit Json files that have an internal array of dictionaries, hitting <ENTER> takes me to the next line, indented, PLUS AN EXTRA SPACE.

I've been playing with every option I can find to try to turn off this extra space, but nothing I do is making a difference. Tab size is 4.

Here's a simple repro:

Start with a Json file consisting of this:
Code: [Select]
{
   foo:
   [
   {
      a:"b"
   },
   {
      c:"d"
   }
   ]
}

Now, position the cursor at the end of the line above c:"d", right after the opening curly brace.

Now, hit <ENTER>. You will see that you're on a new line above c:"d"... but with an extra space!!!.

How can I stop SlickEdit from adding this extra space?

Note: I'm using SlickEdit 2020, 25.0.2.0, Brief key emulation, tab stops at 4 characters.


patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1818
  • Hero Points: 151
Re: How to prevent this extra space getting added to JSon/Javascript
« Reply #1 on: September 08, 2021, 12:04:27 PM »
Sounds like your syntax indent is set to 4 instead of 3.  Go to Tools -> Options -> Languages -> Web Authoring Languages -> JSON -> Formatting, press the Edit button, go to the General setting and change syntax indent to 3.

spongyryno

  • Community Member
  • Posts: 48
  • Hero Points: 0
Re: How to prevent this extra space getting added to JSon/Javascript
« Reply #2 on: September 08, 2021, 03:07:22 PM »
It's a requirement that the tab stops be at 4 for all languages. Right now, most things work... except for the case I mentioned in the original post.

If I change this to 3, now the entire language will be broken, and I'd need to resort to VSCode to edit JSon and Javascript. I don't want to do that.

FWIW, this works correctly in VS2019... just not VS2020. I keep finding more and more regressions in VS2020.

How can I get it to work with VS2020?

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1818
  • Hero Points: 151
Re: How to prevent this extra space getting added to JSon/Javascript
« Reply #3 on: September 08, 2021, 08:25:06 PM »
Maybe I misunderstand what you're seeing.  Could you post your user.cfg.xml file from your configuration directory?  That will allow me to see if I can reproduce getting extra spaces different from the Syntax Indent setting and narrow it down.  I haven't been able to get anything like that with clean, or my othe r test configurations.  Could be a setting difference I'm not seeing.

spongyryno

  • Community Member
  • Posts: 48
  • Hero Points: 0
Re: How to prevent this extra space getting added to JSon/Javascript
« Reply #4 on: September 08, 2021, 08:42:06 PM »
Sure thing. What's the best way to get that file to you? I zipped it up, but it doesn't look like I can attach it here.

FWIW, here's a link to it on OneDrive: https://spongysoft-my.sharepoint.com/:u:/g/personal/mike_lyonswa_com/EdWdO602VchNnfznGBPslLgB1N42lS8BmbXeuVHpi9WcPA?e=7a0O4U


patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1818
  • Hero Points: 151
Re: How to prevent this extra space getting added to JSon/Javascript
« Reply #5 on: September 08, 2021, 09:05:47 PM »
Pulled it from the link. 

I see that .json files are mapped to Javascript mode by default.  I don't see the extra spaces in Javascript mode, but if I switch to JSON mode, I can reproduce the extra spaces.   That match up with what you're seeing?  (you can see the active mode when you have a file open by looking at the Document menu, and seeing what's after the Select Mode entry). 

I'm investigating the weird spacing in JSON mode...

spongyryno

  • Community Member
  • Posts: 48
  • Hero Points: 0
Re: How to prevent this extra space getting added to JSon/Javascript
« Reply #6 on: September 09, 2021, 12:45:26 PM »
Mine is reversed: the error happens in Javascript mode, but not in JSON mode. However, it defaulted to Javascript mode with *.json files. Not sure why.

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1818
  • Hero Points: 151
Re: How to prevent this extra space getting added to JSon/Javascript
« Reply #7 on: September 09, 2021, 12:54:26 PM »
It looks like ".json" was added as a JavaScript file extension.  You can take out that mapping by going to the Tools -> Options dialog, and under Languages -> Web Authoring Languages -> JavaScript -> General, press the Edit These Extensions button, and delete the json entry.  And then you can go to the JSON entry right below JavaScript, and add the json extension back to the JSON using the same button. 

I'll double check it with the JavaScript mode when I get done with JSON.

[edit]
Also, the pasted example uses spaces for indenting, 3 spaces per indent.  Is that the way the example is formatted on your system, or did it get mangled in the pasting?
« Last Edit: September 09, 2021, 12:56:53 PM by patrick »

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1818
  • Hero Points: 151
Re: How to prevent this extra space getting added to JSon/Javascript
« Reply #8 on: September 09, 2021, 01:12:33 PM »
Actually, the sample file must be the reason I see it differently from you.  If I change the sample to tab indents, then my experience matches what you see - the problem is for in JavaScript mode, and does not occur in JSON mode.

Go ahead and have your JSON files edit in JSON mode.  The indent calculation for JavaScript is much more complicated than JSON, from trying to handle some of the special cases that come up with lambas passed as function parameters.  So I suspect it's just mis-recognizing the type of construct the cursor is in to get this type of extra indent.