Skip to content

Commit

Permalink
Fix split paragraph with multiple text fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
ol0lll committed Apr 17, 2024
1 parent d21e65f commit 51834a0
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion js/build/split_paragraph.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions js/ckeditor5_plugins/split_paragraph/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,14 @@ class SplitParagraph extends Plugin {
afterInit() {
// Set value of the new paragraph.
if (window._splitParagraph) {
console.log(this.editor.sourceElement.dataset.drupalSelector);
console.log(this.editor.sourceElement.dataset.drupalSelector.match(window._splitParagraph.selector.replace(/-[0-9]+-?/, '-[0-9]+-')));
if (typeof window._splitParagraph.data.second === 'string') {
const paragraph = this.editor.sourceElement.closest('tr');
const paragraph = this.editor.sourceElement.closest('tr.draggable');
// this.editor.sourceElement.
// closest('.field--widget-paragraphs').querySelector('tr');
const previousParagraph = paragraph?.previousElementSibling;
if (previousParagraph && previousParagraph.querySelector(`[data-drupal-selector="${window._splitParagraph.selector}"]`)) {
if (previousParagraph && this.editor.sourceElement.dataset.drupalSelector.match(window._splitParagraph.selector.replace(/-[0-9]+-?/, '-[0-9]+-'))) {
// Defer to wait until init is complete.
setTimeout(() => {
this.editor.setData(window._splitParagraph.data.second);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default class SplitParagraphCommand extends Command {
}

// Get paragraph type and position.
const paragraph = sourceElement.closest('.paragraphs-subform').closest('tr');
const paragraph = sourceElement.closest('.paragraphs-subform').closest('tr.draggable');
const paragraphType = paragraph.querySelector('[data-paragraphs-split-text-type]').dataset.paragraphsSplitTextType;
const paragraphDelta = [...paragraph.parentNode.children].filter(el => el.querySelector('.paragraphs-actions')).indexOf(paragraph) + 1;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,6 @@ public function testSplitTextFeature() {
$ck_editor_id_para_1_text_0 = $page->find('xpath', '(//*[@data-drupal-selector="edit-field-paragraphs-1"]//textarea)[1]')->getAttribute('data-ckeditor5-id');
$ck_editor_id_para_1_text_1 = $page->find('xpath', '(//*[@data-drupal-selector="edit-field-paragraphs-1"]//textarea)[2]')->getAttribute('data-ckeditor5-id');
$ck_editor_id_para_1_text_2 = $page->find('xpath', '(//*[@data-drupal-selector="edit-field-paragraphs-1"]//textarea)[3]')->getAttribute('data-ckeditor5-id');

static::assertEquals(
$paragraph_content_0_text_0,
$driver->evaluateScript("Drupal.CKEditor5Instances.get('$ck_editor_id_para_0_text_0').getData();")
Expand All @@ -417,15 +416,11 @@ public function testSplitTextFeature() {
$driver->evaluateScript("Drupal.CKEditor5Instances.get('$ck_editor_id_para_0_text_2').getData();")
);
static::assertEquals(
// @todo Fix me, order should be different.
// '',
$paragraph_content_1,
'',
$driver->evaluateScript("Drupal.CKEditor5Instances.get('$ck_editor_id_para_1_text_0').getData();")
);
static::assertEquals(
// Fix me, order should be different.
// $paragraph_content_1,
'',
$paragraph_content_1,
$driver->evaluateScript("Drupal.CKEditor5Instances.get('$ck_editor_id_para_1_text_1').getData();")
);
static::assertEquals(
Expand Down

0 comments on commit 51834a0

Please sign in to comment.