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

Add indent and outdent toolbar buttons #555

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,8 @@ fullscreen | toggleFullScreen | Toggle Fullscreen<br>fa fa-arrows-alt no-disable
guide | [This link](https://www.markdownguide.org/basic-syntax/) | Markdown Guide<br>fa fa-question-circle
undo | undo | Undo<br>fa fa-undo
redo | redo | Redo<br>fa fa-redo
indent | indent | Indent<br>fa fa-indent
outdent | outdent | Outdent<br>fa fa-outdent


### Toolbar customization
Expand Down
52 changes: 52 additions & 0 deletions src/js/easymde.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ var bindings = {
'redo': redo,
'toggleSideBySide': toggleSideBySide,
'toggleFullScreen': toggleFullScreen,
'indent': indent,
'outdent': outdent,
};

var shortcuts = {
Expand Down Expand Up @@ -1081,6 +1083,29 @@ function togglePreview(editor) {

}


/**
* Indent action.
* @param {EasyMDE} editor
*/
function indent(editor) {
var cm = editor.codemirror;
cm.execCommand('tabAndIndentMarkdownList');
cm.focus();
}


/**
* Outdent action.
* @param {EasyMDE} editor
*/
function outdent(editor) {
var cm = editor.codemirror;
cm.execCommand('shiftTabAndUnindentMarkdownList');
cm.focus();
}


function _replaceSelection(cm, active, startEnd, url) {
if (cm.getWrapperElement().lastChild.classList.contains('editor-preview-active'))
return;
Expand Down Expand Up @@ -1484,6 +1509,8 @@ var iconClassMap = {
'guide': 'fa fa-question-circle',
'undo': 'fa fa-undo',
'redo': 'fa fa-repeat fa-redo',
'indent': 'fa fa-indent',
'outdent': 'fa fa-outdent',
};

var toolbarBuiltInButtons = {
Expand Down Expand Up @@ -1672,6 +1699,23 @@ var toolbarBuiltInButtons = {
noDisable: true,
title: 'Redo',
},
'separator-6': {
name: 'separator-6',
},
'indent': {
name: 'indent',
action: indent,
className: iconClassMap['indent'],
noDisable: true,
title: 'Indent',
},
'outdent': {
name: 'outdent',
action: outdent,
className: iconClassMap['outdent'],
noDisable: true,
title: 'Outdent',
},
};

var insertTexts = {
Expand Down Expand Up @@ -2905,6 +2949,8 @@ EasyMDE.redo = redo;
EasyMDE.togglePreview = togglePreview;
EasyMDE.toggleSideBySide = toggleSideBySide;
EasyMDE.toggleFullScreen = toggleFullScreen;
EasyMDE.indent = indent;
EasyMDE.outdent = outdent;

/**
* Bind instance methods for exports.
Expand Down Expand Up @@ -2987,6 +3033,12 @@ EasyMDE.prototype.toggleSideBySide = function () {
EasyMDE.prototype.toggleFullScreen = function () {
toggleFullScreen(this);
};
EasyMDE.prototype.indent = function () {
indent(this);
};
EasyMDE.prototype.outdent = function () {
outdent(this);
};

EasyMDE.prototype.isPreviewActive = function () {
var cm = this.codemirror;
Expand Down
6 changes: 5 additions & 1 deletion types/easymde.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ type ToolbarButton =
| 'preview'
| 'side-by-side'
| 'fullscreen'
| 'guide';
| 'guide'
| 'indent'
| 'outdent';

declare namespace EasyMDE {

Expand Down Expand Up @@ -287,6 +289,8 @@ declare class EasyMDE {
static toggleFullScreen: (editor: EasyMDE) => void;
static undo: (editor: EasyMDE) => void;
static redo: (editor: EasyMDE) => void;
static indent: (editor: EasyMDE) => void;
static outdent: (editor: EasyMDE) => void;
}

export as namespace EasyMDE;
Expand Down