Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
✨ add spellcheck toggle (#697)
Browse files Browse the repository at this point in the history
closes TryGhost/Ghost#8461
- adds toggle spellcheck button to the `gh-markdown-editor` toolbar
- adds custom styles to fake a spellcheck icon
- updates `simplemde` fork
  - adds `spellcheck` to the list of toolbar buttons that don't have their `active` class removed based on cursor position
  - removes bundled `marked` dependency that we no longer use
  • Loading branch information
kevinansfield authored and aileen committed May 18, 2017
1 parent d49484a commit ef9381b
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
29 changes: 28 additions & 1 deletion app/components/gh-markdown-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ export default Component.extend({
title: 'Toggle Fullscreen'
},
'|',
{
name: 'spellcheck',
action: () => {
this._toggleSpellcheck();
},
className: 'fa fa-check',
title: 'Toggle Spellcheck'
},
{
name: 'guide',
action: () => {
Expand Down Expand Up @@ -207,11 +215,12 @@ export default Component.extend({
cm.replaceSelection(text, 'end');
},

// mark the split-pane/full-screen buttons active when they're active
// mark the split-pane/full-screen/spellcheck buttons active when they're active
_updateButtonState() {
if (this._editor) {
let fullScreenButton = this._editor.toolbarElements.fullscreen;
let sideBySideButton = this._editor.toolbarElements['side-by-side'];
let spellcheckButton = this._editor.toolbarElements.spellcheck;

if (this.get('_isFullScreen')) {
fullScreenButton.classList.add('active');
Expand All @@ -224,6 +233,12 @@ export default Component.extend({
} else {
sideBySideButton.classList.remove('active');
}

if (this._editor.codemirror.getOption('mode') === 'spell-checker') {
spellcheckButton.classList.add('active');
} else {
spellcheckButton.classList.remove('active');
}
}
},

Expand Down Expand Up @@ -313,6 +328,18 @@ export default Component.extend({
this._editor.togglePreview();
},

_toggleSpellcheck() {
let cm = this._editor.codemirror;

if (cm.getOption('mode') === 'spell-checker') {
cm.setOption('mode', 'markdown');
} else {
cm.setOption('mode', 'spell-checker');
}

this._updateButtonState();
},

willDestroyElement() {
if (this.get('_isSplitScreen')) {
this._disconnectSplitPreview();
Expand Down
22 changes: 22 additions & 0 deletions app/styles/layouts/editor.css
Original file line number Diff line number Diff line change
Expand Up @@ -381,3 +381,25 @@
.editor-toolbar a.disabled:hover {
border: none;
}

.editor-toolbar .fa-check {
position: relative;
vertical-align: bottom;
}
.editor-toolbar .fa-check:before {
font-size: 14px;
position: absolute;
line-height: 14px;
right: 3px;
bottom: 4px;
}

.editor-toolbar .fa-check:after {
content: 'abc';
font-family: var(--font-family);
position: absolute;
left: 4px;
font-size: 9px;
top: 6px;
line-height: 9px;
}
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7458,7 +7458,7 @@ simple-is@~0.2.0:

"simplemde@https://github.com/kevinansfield/simplemde-markdown-editor.git#ghost":
version "1.11.2"
resolved "https://github.com/kevinansfield/simplemde-markdown-editor.git#29f69b859b19f6ecbc678780290e388298b308c4"
resolved "https://github.com/kevinansfield/simplemde-markdown-editor.git#05ba8d8ff395b148258743a31ef7e07ae5579d3e"
dependencies:
codemirror "*"
codemirror-spell-checker "*"
Expand Down

0 comments on commit ef9381b

Please sign in to comment.