This is a function that will be called when pressing tab when writing inside a text area element in html. This will create 4 spaces just like a tab.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('#textarea').keydown(function (e) { | |
var keyCode = e.keyCode || e.which; | |
if (keyCode === $.ui.keyCode.TAB) { | |
e.preventDefault(); | |
const TAB_SIZE = 4; | |
// The one-liner that does the magic | |
document.execCommand('insertText', false, ' '.repeat(TAB_SIZE)); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment