-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9bf3292
commit 9e9a4e7
Showing
3 changed files
with
160 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
import {svg} from '../../svg.js'; | ||
|
||
export function easyMDEToolbarActions(EasyMDE, editor) { | ||
const actions = { | ||
'|': '|', | ||
'heading-1': { | ||
action: EasyMDE.toggleHeading1, | ||
icon: svg('octicon-heading'), | ||
title: 'Heading', | ||
}, | ||
'heading-2': { | ||
action: EasyMDE.toggleHeading2, | ||
icon: svg('octicon-heading'), | ||
title: 'Heading', | ||
}, | ||
'heading-3': { | ||
action: EasyMDE.toggleHeading3, | ||
icon: svg('octicon-heading'), | ||
title: 'Heading', | ||
}, | ||
'bold': { | ||
action: EasyMDE.toggleBold, | ||
icon: svg('octicon-bold'), | ||
title: 'Bold', | ||
}, | ||
'italic': { | ||
action: EasyMDE.toggleItalic, | ||
icon: svg('octicon-italic'), | ||
title: 'Italic', | ||
}, | ||
'strikethrough': { | ||
action: EasyMDE.toggleStrikethrough, | ||
icon: svg('octicon-strikethrough'), | ||
title: 'Strikethrough', | ||
}, | ||
'quote': { | ||
action: EasyMDE.toggleBlockquote, | ||
icon: svg('octicon-quote'), | ||
title: 'Quote', | ||
}, | ||
'code': { | ||
action: EasyMDE.toggleCodeBlock, | ||
icon: svg('octicon-code'), | ||
title: 'Code', | ||
}, | ||
'link': { | ||
action: EasyMDE.drawLink, | ||
icon: svg('octicon-link'), | ||
title: 'Link', | ||
}, | ||
'unordered-list': { | ||
action: EasyMDE.toggleUnorderedList, | ||
icon: svg('octicon-list-unordered'), | ||
title: 'Unordered List', | ||
}, | ||
'ordered-list': { | ||
action: EasyMDE.toggleOrderedList, | ||
icon: svg('octicon-list-ordered'), | ||
title: 'Ordered List', | ||
}, | ||
'image': { | ||
action: EasyMDE.drawImage, | ||
icon: svg('octicon-image'), | ||
title: 'Image', | ||
}, | ||
'table': { | ||
action: EasyMDE.drawTable, | ||
icon: svg('octicon-table'), | ||
title: 'Table', | ||
}, | ||
'horizontal-rule': { | ||
action: EasyMDE.drawHorizontalRule, | ||
icon: svg('octicon-horizontal-rule'), | ||
title: 'Horizontal Rule', | ||
}, | ||
'preview': { | ||
action: EasyMDE.togglePreview, | ||
icon: svg('octicon-eye'), | ||
title: 'Preview', | ||
}, | ||
'fullscreen': { | ||
action: EasyMDE.toggleFullScreen, | ||
icon: svg('octicon-screen-full'), | ||
title: 'Fullscreen', | ||
}, | ||
'side-by-side': { | ||
action: EasyMDE.toggleSideBySide, | ||
icon: svg('octicon-columns'), | ||
title: 'Side by Side', | ||
}, | ||
|
||
// gitea's custom actions | ||
'gitea-checkbox-empty': { | ||
action(e) { | ||
const cm = e.codemirror; | ||
cm.replaceSelection(`\n- [ ] ${cm.getSelection()}`); | ||
cm.focus(); | ||
}, | ||
icon: svg('gitea-empty-checkbox'), | ||
title: 'Add Checkbox (empty)', | ||
}, | ||
'gitea-checkbox-checked': { | ||
action(e) { | ||
const cm = e.codemirror; | ||
cm.replaceSelection(`\n- [x] ${cm.getSelection()}`); | ||
cm.focus(); | ||
}, | ||
icon: svg('octicon-checkbox'), | ||
title: 'Add Checkbox (checked)', | ||
}, | ||
'gitea-switch-to-textarea': { | ||
action: () => { | ||
editor.userPreferredEditor = 'textarea'; | ||
editor.switchToTextarea(); | ||
}, | ||
icon: svg('octicon-arrow-switch'), | ||
title: 'Revert to simple textarea', | ||
}, | ||
'gitea-code-inline': { | ||
action(e) { | ||
const cm = e.codemirror; | ||
const selection = cm.getSelection(); | ||
cm.replaceSelection(`\`${selection}\``); | ||
if (!selection) { | ||
const cursorPos = cm.getCursor(); | ||
cm.setCursor(cursorPos.line, cursorPos.ch - 1); | ||
} | ||
cm.focus(); | ||
}, | ||
icon: svg('octicon-chevron-right'), | ||
title: 'Add Inline Code', | ||
} | ||
}; | ||
for (const action in actions) { | ||
if (action !== '|') { | ||
actions[action].name = action; | ||
} | ||
} | ||
return actions; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters