Skip to content

Commit

Permalink
feat: turning on a native browser spell-checker
Browse files Browse the repository at this point in the history
According to Ionaru/easy-markdown-editor#143

Signed-off-by: Dmytro Borysovskyi 🦁
  • Loading branch information
dimabory committed Jan 6, 2021
1 parent 5eff8d3 commit a370d32
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions frontend/static/js/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ const imageUploadOptions = {
"image/jpg",
"image/gif",
"video/mp4",
"video/quicktime" // .mov (macOS' default record format)
"video/quicktime", // .mov (macOS' default record format)
],
extraHeaders: {
"Accept": "application/json",
Accept: "application/json",
},
extraParams: {
code: imageUploadCode,
Expand All @@ -36,10 +36,11 @@ const imageUploadOptions = {
const defaultMarkdownEditorOptions = {
autoDownloadFontAwesome: false,
spellChecker: false,
nativeSpellcheck: true,
forceSync: true,
status: false,
inputStyle: "textarea",
tabSize: 4
inputStyle: "contenteditable",
tabSize: 4,
};

/**
Expand All @@ -58,18 +59,18 @@ function createMarkdownEditor(element, options) {

// overriding default CodeMirror shortcuts
editor.codemirror.addKeyMap({
'Home': 'goLineLeft', // move the cursor to the left side of the visual line it is on
'End': 'goLineRight', // move the cursor to the right side of the visual line it is on
Home: "goLineLeft", // move the cursor to the left side of the visual line it is on
End: "goLineRight", // move the cursor to the right side of the visual line it is on
});

// adding ability to fire events on the hidden element
if (element.dataset.listen) {
const events = element.dataset.listen.split(' ')
events.forEach(event => {
const events = element.dataset.listen.split(" ");
events.forEach((event) => {
try {
editor.codemirror.on(event, e => e.getTextArea().dispatchEvent(new Event(event)))
editor.codemirror.on(event, (e) => e.getTextArea().dispatchEvent(new Event(event)));
} catch (e) {
console.warn('Invalid event provided', event)
console.warn("Invalid event provided", event);
}
});
}
Expand Down Expand Up @@ -190,7 +191,7 @@ const App = {
title: "Insert code",
},
],
})
});

return [...editors, editor];
},
Expand All @@ -200,7 +201,7 @@ const App = {
const invisibleMarkdownEditors = [...document.querySelectorAll(".markdown-editor-invisible")].reduce(
(editors, element) => {
const editor = createMarkdownEditor(element, {
toolbar: false
toolbar: false,
});

return [...editors, editor];
Expand Down

0 comments on commit a370d32

Please sign in to comment.