Last active
December 13, 2021 13:47
-
-
Save Frelseren/4658a203ae626d05db6f38384befbd31 to your computer and use it in GitHub Desktop.
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
import { LightningElement } from 'lwc'; | |
export default class TestRichInput extends LightningElement { | |
value = ` | |
<table> | |
<thead> | |
<tr> | |
<td>Header 1</td> | |
<tr> | |
<tr> | |
<td>Header 2</td> | |
<tr> | |
</thead> | |
<tbody> | |
<tr> | |
<td>Cell 1</td> | |
<tr> | |
<tr> | |
<td>Cell 2</td> | |
<tr> | |
</tbody> | |
</table> | |
` | |
getCaret(el) { | |
if (el.selectionStart) { | |
return el.selectionStart; | |
} else if (document.selection) { | |
el.focus(); | |
var r = document.selection.createRange(); | |
if (r == null) { | |
return 0; | |
} | |
var re = el.createTextRange(), | |
rc = re.duplicate(); | |
re.moveToBookmark(r.getBookmark()); | |
rc.setEndPoint('EndToStart', re); | |
return rc.text.length; | |
} | |
return 0; | |
} | |
handleKeyDown(e) { | |
const key = e.keyCode; | |
const input = this.template.querySelector('c-custom-input'); | |
const pos = document.activeElement.selectionStart; | |
const activeElement = document.activeElement; | |
console.log(pos) | |
console.log(activeElement) | |
console.log(input.getContent()) | |
if (key === 8) { | |
e.preventDefault(); | |
e.stopPropagation(); | |
input.setCustomContent(this.value); | |
} | |
this.value = input.getContent(); | |
console.log(this.value); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment