Use custom element on text editor element

This commit is contained in:
sadick254 2021-08-17 20:29:47 +03:00
parent 7df9cdb0a8
commit 510d04bffe
No known key found for this signature in database
GPG Key ID: FB51CF448C1FD089
3 changed files with 17 additions and 8 deletions

View File

@ -14,7 +14,7 @@ describe('TextEditorElement', () => {
});
function buildTextEditorElement(options = {}) {
const element = new TextEditorElement();
const element = TextEditorElement.createTextEditorElement();
element.setUpdatedSynchronously(false);
if (options.attach !== false) jasmine.attachToDOM(element);
return element;

View File

@ -67,7 +67,7 @@ module.exports = class TextEditorComponent {
} else {
if (!TextEditorElement)
TextEditorElement = require('./text-editor-element');
this.element = new TextEditorElement();
this.element = TextEditorElement.createTextEditorElement();
}
this.element.initialize(this);
this.virtualNode = $('atom-text-editor');

View File

@ -29,7 +29,8 @@ class TextEditorElement extends HTMLElement {
return this;
}
createdCallback() {
constructor() {
super();
this.emitter = new Emitter();
this.initialText = this.textContent;
if (this.tabIndex == null) this.tabIndex = -1;
@ -39,16 +40,20 @@ class TextEditorElement extends HTMLElement {
this.addEventListener('blur', event => this.getComponent().didBlur(event));
}
attachedCallback() {
connectedCallback() {
this.getComponent().didAttach();
this.emitter.emit('did-attach');
}
detachedCallback() {
disconnectedCallback() {
this.emitter.emit('did-detach');
this.getComponent().didDetach();
}
static get observedAttributes() {
return ['mini', 'placeholder-text', 'gutter-hidden', 'readonly'];
}
attributeChangedCallback(name, oldValue, newValue) {
if (this.component) {
switch (name) {
@ -352,8 +357,12 @@ class TextEditorElement extends HTMLElement {
getFirstVisibleScreenColumn() {
return this.getModel().getFirstVisibleScreenColumn();
}
static createTextEditorElement() {
return document.createElement('atom-text-editor');
}
}
module.exports = document.registerElement('atom-text-editor', {
prototype: TextEditorElement.prototype
});
window.customElements.define('atom-text-editor', TextEditorElement);
module.exports = TextEditorElement;