Skip to content

Instantly share code, notes, and snippets.

@Frelseren
Last active December 13, 2021 13:47
Show Gist options
  • Save Frelseren/4658a203ae626d05db6f38384befbd31 to your computer and use it in GitHub Desktop.
Save Frelseren/4658a203ae626d05db6f38384befbd31 to your computer and use it in GitHub Desktop.
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