Skip to content

Instantly share code, notes, and snippets.

@kuuote
Created November 17, 2020 11:54
Show Gist options
  • Save kuuote/ae78ac5a3de14a938441cc165e9a9351 to your computer and use it in GitHub Desktop.
Save kuuote/ae78ac5a3de14a938441cc165e9a9351 to your computer and use it in GitHub Desktop.
HTML側のインデントを抜き去れるinput
<script>
let indent = 0;
function redraw() {
const dom = document.querySelector('span');
dom.innerHTML = ' '.repeat(indent);
}
function handle() {
const dom = document.querySelector('input');
if(dom.selectionStart === 0) {
if(this.event.keyCode == 8) {
indent = Math.max(0, indent - 1);
redraw();
return false;
}
if(this.event.keyCode == 32) {
indent += 1;
redraw();
return false;
}
}
return true;
}
</script>
<span></span>・<input autofocus onkeydown="return handle()"></input>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment