question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JavaScript Mode Forces Tabs

See original GitHub issue

http://codemirror.net/mode/javascript/index.html

editor.setOption("indentWithTabs", false);

Should stop inserting tabs and start using spaces, but still inserts tabs.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
markhillardcommented, Dec 8, 2018

@chriscoyier, I know this is an old issue, but I came across the following code via this Stack Overflow question / example: http://jsfiddle.net/nktvt8vf/12/

extraKeys: {
    'Tab': 'indentMore'
}

This maintains normal tab behavior (spaces/tabs depending on your settings) on an empty line as well as multi-line indenting, but also indents the beginning of a line of code. It also plays nice with Emmet.

I could see how this might be useful in CodePen… thought I’d give you a shout.

0reactions
PullJoshcommented, Dec 10, 2018

This remains an issue that has nothing to do with the CodeMirror core, but I found this page when I had the same problem with emmet and eventually came to a solution that I thought would be valuable to share.


Previously, I had the following settings:

extraKeys: {
  Tab: 'emmetExpandAbbreviation',
  Enter: 'emmetInsertLineBreak'
}

This wasn’t working because emmet would sometimes choose to indent automatically using two spaces, but whenever there was nothing to expand, emmet would pass off the tab key event to the default CodeMirror handler, which indented using a tab character.

The solution for this was to handle the pass-off action manually:

extraKeys: {
  Tab: cm => {
    // Default emmet behavior
    if (cm.execCommand('emmetExpandAbbreviation') === true) return

    // Otherwise indent with spaces, not tabs
    const spaces = Array(cm.getOption('indentUnit') + 1).join(' ')
    cm.replaceSelection(spaces)
  },
  Enter: 'emmetInsertLineBreak'
}

Again, sorry for continuing an issue that’s not a problem with CodeMirror directly, but I think it’s valuable to have this answer here to save others time in the future.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JavaScript Mode Forces Tabs · Issue #3278 · codemirror ...
And that works great in the editor for HTML and CSS, but for a reason I haven't been able to figure out, fails...
Read more >
Forcing IE into opening new tab instead of window? ...
I want a script that makes a user's Internet Explorer open a new tab instead of a new window whenever someone clicks on...
Read more >
How To Create Tabs
Create buttons to open specific tab content. All <div> elements with class="tabcontent" are hidden by default (with CSS & JS). When the user...
Read more >
Code Style. JavaScript | WebStorm Documentation
Use tab character. If this checkbox is selected, tab characters are used: On pressing the Tab key. For indentation. For reformatting code.
Read more >
How to Always Open Files in a New Tab - VSCode
Simply right-click on the Preview Mode tab on the tab at the top of your screen (while it's italicized) and click on "Keep...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found