* IndentHelper provides methods that allow manual and smart indentation in
* textareas. It supports line indent/unindent, selection indent/unindent,
* auto indentation on newlines, and smart deletion of indents with backspace.
*/
exportdefaultclassIndentHelper{
/**
* Creates a new IndentHelper and binds it to the given `textarea`. You can provide a custom indent sequence in the second parameter, but the `newline` and `backspace` operations may work funny if the indent sequence isn't spaces only.
* Tests if a KeyboardEvent corresponds exactly to a keystroke.
*
* This function avoids hacking around an old version of Mousetrap, which we ship at the moment. It should be removed after we upgrade to the newest Mousetrap. See:
* // Matches the enter key with exactly zero modifiers
* keystroke(event, 13)
*
* @example
* // Matches Control-Shift-Z
* keystroke(event, 90, 'cs')
*
* @param e The KeyboardEvent to test.
* @param keyCode The key code of the key to test. Why keycodes? IE/Edge don't support the more convenient `key` and `code` properties.
* @param modifiers A string of modifiers keys. Each modifier key is represented by one character. The set of pressed modifier keys must match the given string exactly. Available options are 'a' for Alt/Option, 'c' for Control, 'm' for Meta/Command, 's' for Shift, and 'l' for the leader key (Meta on MacOS and Control otherwise).
* @returns {boolean} True if the KeyboardEvent corresponds to the given keystroke.
* UndoStack provides a custom implementation of an undo/redo engine. It was originally written for GitLab's Markdown editor (`gl_form.js`), whose rich text editing capabilities broke native browser undo/redo behaviour.
*
* UndoStack supports predictable undos/redos, debounced saves, maximum history length, and duplicate detection.
*
* Usage:
* - `stack = new UndoStack();`
* - Saves a state to the stack with `stack.save(state)`.
* - Get the current state with `stack.current()`.
* - Revert to the previous state with `stack.undo()`.
* - Redo a previous undo with `stack.redo()`;
* - Queue a future save with `stack.scheduleSave(state, delay)`. Useful for text editors.
* - See the full undo history in `stack.history`.
*/
exportdefaultclassUndoStack{
constructor(maxLength=1000){
this.clear();
this.maxLength=maxLength;
// If you're storing reference-types in the undo stack, you might want to
// reassign this property to some deep-equals function.
this.comparator=(a,b)=>a===b;
}
current(){
if(this.cursor===-1){
returnundefined;
}
returnthis.history[this.cursor];
}
isEmpty(){
returnthis.history.length===0;
}
clear(){
this.clearPending();
this.history=[];
this.cursor=-1;
}
save(state){
this.clearPending();
if(this.comparator(state,this.current())){
// Don't save state if it's the same as the current state
=s_('Editor|%{mdLinkStart}Markdown%{mdLinkEnd} and %{actionsLinkStart}quick actions%{actionsLinkEnd} are supported').html_safe%{mdLinkStart: md_link_start,mdLinkEnd: link_end,actionsLinkStart: actions_link_start,actionsLinkEnd: link_end}
-else
is
supported
=s_('Editor|%{mdLinkStart}Markdown is supported%{mdLinkEnd}').html_safe%{mdLinkStart: md_link_start,mdLinkEnd: link_end}