Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Jenuel Oras Ganawed BroJenuel

🏠
Working from home
View GitHub Profile
@BroJenuel
BroJenuel / presstab.js
Last active Sep 22, 2020
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.
View presstab.js
$('#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));