Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBX-8850: Focus bug in rich text editor #188

Merged
merged 2 commits into from
Nov 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class IbexaCustomTagUI extends Plugin {
this.addCustomTag = this.addCustomTag.bind(this);

this.isNew = false;
this.activeModelElement = null;

let timeoutId = null;
this.listenTo(this.balloon.view, 'change:top', () => {
Expand Down Expand Up @@ -95,8 +96,7 @@ class IbexaCustomTagUI extends Plugin {
const formView = new IbexaCustomTagFormView({ locale: this.editor.locale });

this.listenTo(formView, 'save-custom-tag', () => {
const modelElement = this.editor.model.document.selection.getSelectedElement();
const values = modelElement.getAttribute('values');
const values = this.activeModelElement.getAttribute('values');
const newValues = { ...values };

this.isNew = false;
Expand All @@ -112,7 +112,7 @@ class IbexaCustomTagUI extends Plugin {
});

this.editor.model.change((writer) => {
writer.setAttribute('values', newValues, modelElement);
writer.setAttribute('values', newValues, this.activeModelElement);
});

this.reinitAttributesView();
Expand Down Expand Up @@ -151,8 +151,9 @@ class IbexaCustomTagUI extends Plugin {
}

showForm() {
const modelElement = this.editor.model.document.selection.getSelectedElement();
const values = modelElement.getAttribute('values');
this.activeModelElement = this.editor.model.document.selection.getSelectedElement();
dew326 marked this conversation as resolved.
Show resolved Hide resolved

const values = this.activeModelElement.getAttribute('values');
const parsedValues = Object.entries(values).reduce((output, [key, value]) => {
if (this.config.attributes[key]?.type === 'boolean') {
return {
Expand Down Expand Up @@ -189,14 +190,14 @@ class IbexaCustomTagUI extends Plugin {
}

removeCustomTag() {
const modelElement = this.editor.model.document.selection.getSelectedElement();

this.editor.model.change((writer) => {
if (this.balloon.hasView(this.attributesView)) {
this.hideAttributes();
}

writer.remove(modelElement);
writer.remove(this.activeModelElement);

this.activeModelElement = null;
});
}

Expand All @@ -209,13 +210,16 @@ class IbexaCustomTagUI extends Plugin {
}

addCustomTag() {
if (this.balloon.hasView(this.formView)) {
return;
}

const values = Object.entries(this.config.attributes).reduce((outputValues, [attributeName, config]) => {
outputValues[attributeName] = config.defaultValue;

return outputValues;
}, {});

this.editor.focus();
this.editor.execute('insertIbexaCustomTag', { customTagName: this.componentName, values });

if (this.hasAttributes()) {
Expand Down
Loading