Created
November 17, 2020 11:54
-
-
Save kuuote/ae78ac5a3de14a938441cc165e9a9351 to your computer and use it in GitHub Desktop.
HTML側のインデントを抜き去れるinput
This file contains hidden or 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
<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