better newline support
This commit is contained in:
19
assets/js/hooks.js
Normal file
19
assets/js/hooks.js
Normal file
@@ -0,0 +1,19 @@
|
||||
const Hooks = {};
|
||||
|
||||
Hooks.EnterToNewline = {
|
||||
mounted() {
|
||||
this.el.addEventListener('keydown', (e) => {
|
||||
if (e.key === 'Enter' && !e.shiftKey) {
|
||||
e.preventDefault();
|
||||
|
||||
const cursorPos = this.el.selectionStart;
|
||||
const value = this.el.value;
|
||||
|
||||
this.el.value = value.slice(0, cursorPos) + '\\n' + value.slice(cursorPos);
|
||||
this.el.selectionStart = this.el.selectionEnd = cursorPos + 2;
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
export default Hooks;
|
||||
Reference in New Issue
Block a user