Skip to content

Commit

Permalink
Merge branch 'MDL-68639-master' of https://github.com/xcaro/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols authored and ilyatregubov committed Aug 19, 2021
2 parents 84077e5 + 7bcd587 commit 517fe29
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 1 deletion.
Expand Up @@ -71,6 +71,9 @@ Y.namespace('M.atto_indent').Button = Y.Base.create('button', Y.M.editor_atto.Ed
// Run the indent command.
document.execCommand('indent', false, null);

// Fix indent list item.
this.fixupListItemsAfterIndent();

// Get all blockquotes, both existing and new.
blockquotes = this.editor.all('blockquote');

Expand Down Expand Up @@ -195,6 +198,28 @@ Y.namespace('M.atto_indent').Button = Y.Base.create('button', Y.M.editor_atto.Ed
indent.replace(clone);
indent = editor.one('.editor-indent');
}
},
/**
* Fixup for list item after indent.
*
* @method fixupListItemsAfterIndent
*/
fixupListItemsAfterIndent: function() {
var selection = window.rangy.getSelection(),
rootelement = this.editor.getDOMNode(),
listelement = selection.anchorNode.parentElement;

listelement = listelement.closest('ol, ul');
if (!(listelement && rootelement.contains(listelement))) {
return;
}

// We will move the child list into previous list item of the parent.
var previous = listelement.previousElementSibling;
if (previous && previous.tagName === 'LI') {
previous.appendChild(listelement);
selection.collapseToEnd();
}
}
});

Expand Down

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

Expand Up @@ -71,6 +71,9 @@ Y.namespace('M.atto_indent').Button = Y.Base.create('button', Y.M.editor_atto.Ed
// Run the indent command.
document.execCommand('indent', false, null);

// Fix indent list item.
this.fixupListItemsAfterIndent();

// Get all blockquotes, both existing and new.
blockquotes = this.editor.all('blockquote');

Expand Down Expand Up @@ -195,6 +198,28 @@ Y.namespace('M.atto_indent').Button = Y.Base.create('button', Y.M.editor_atto.Ed
indent.replace(clone);
indent = editor.one('.editor-indent');
}
},
/**
* Fixup for list item after indent.
*
* @method fixupListItemsAfterIndent
*/
fixupListItemsAfterIndent: function() {
var selection = window.rangy.getSelection(),
rootelement = this.editor.getDOMNode(),
listelement = selection.anchorNode.parentElement;

listelement = listelement.closest('ol, ul');
if (!(listelement && rootelement.contains(listelement))) {
return;
}

// We will move the child list into previous list item of the parent.
var previous = listelement.previousElementSibling;
if (previous && previous.tagName === 'LI') {
previous.appendChild(listelement);
selection.collapseToEnd();
}
}
});

Expand Down
25 changes: 25 additions & 0 deletions lib/editor/atto/plugins/indent/yui/src/button/js/button.js
Expand Up @@ -69,6 +69,9 @@ Y.namespace('M.atto_indent').Button = Y.Base.create('button', Y.M.editor_atto.Ed
// Run the indent command.
document.execCommand('indent', false, null);

// Fix indent list item.
this.fixupListItemsAfterIndent();

// Get all blockquotes, both existing and new.
blockquotes = this.editor.all('blockquote');

Expand Down Expand Up @@ -193,5 +196,27 @@ Y.namespace('M.atto_indent').Button = Y.Base.create('button', Y.M.editor_atto.Ed
indent.replace(clone);
indent = editor.one('.editor-indent');
}
},
/**
* Fixup for list item after indent.
*
* @method fixupListItemsAfterIndent
*/
fixupListItemsAfterIndent: function() {
var selection = window.rangy.getSelection(),
rootelement = this.editor.getDOMNode(),
listelement = selection.anchorNode.parentElement;

listelement = listelement.closest('ol, ul');
if (!(listelement && rootelement.contains(listelement))) {
return;
}

// We will move the child list into previous list item of the parent.
var previous = listelement.previousElementSibling;
if (previous && previous.tagName === 'LI') {
previous.appendChild(listelement);
selection.collapseToEnd();
}
}
});

0 comments on commit 517fe29

Please sign in to comment.