From 758ad80841a69ec3dd4c767931bdb17ed4d2381d Mon Sep 17 00:00:00 2001 From: Otto G Date: Thu, 6 Jun 2019 19:08:05 +0100 Subject: [PATCH] Add toolbar actions logic --- app/src/components/panel/PanelContent.js | 42 ++++++++++++++++++++++++ app/src/components/panel/PanelTabBar.js | 24 ++++++++++---- 2 files changed, 59 insertions(+), 7 deletions(-) diff --git a/app/src/components/panel/PanelContent.js b/app/src/components/panel/PanelContent.js index b2b7c2d..e9b7248 100644 --- a/app/src/components/panel/PanelContent.js +++ b/app/src/components/panel/PanelContent.js @@ -107,12 +107,48 @@ const PanelContent = ({ setCodemirrorInstance(_codemirrorInstance) } + const setSelectionSize = () => { + codemirrorInstance.doc.replaceSelection( + '# ' + codemirrorInstance.doc.getSelection() + ) + } + + const setSelectionUnorderedList = () => { + codemirrorInstance.doc.replaceSelection( + '\n* ' + codemirrorInstance.doc.getSelection() + '\n' + ) + } + const setSelectionBold = () => { codemirrorInstance.doc.replaceSelection( '**' + codemirrorInstance.doc.getSelection() + '**' ) } + const setSelectionItalic = () => { + codemirrorInstance.doc.replaceSelection( + '*' + codemirrorInstance.doc.getSelection() + '*' + ) + } + + const setSelectionLink = () => { + codemirrorInstance.doc.replaceSelection( + '[' + codemirrorInstance.doc.getSelection() + ']()' + ) + } + + const setSelectionCode = () => { + codemirrorInstance.doc.replaceSelection( + '`' + codemirrorInstance.doc.getSelection() + '`' + ) + } + + const setSelectionQuote = () => { + codemirrorInstance.doc.replaceSelection( + '> ' + codemirrorInstance.doc.getSelection() + ) + } + const saveBlock = async () => { switch (editorType) { case 0: @@ -145,6 +181,12 @@ const PanelContent = ({ handleChange={handleChange} screenIndex={screenIndex} setSelectionBold={setSelectionBold} + setSelectionCode={setSelectionCode} + setSelectionItalic={setSelectionItalic} + setSelectionLink={setSelectionLink} + setSelectionQuote={setSelectionQuote} + setSelectionSize={setSelectionSize} + setSelectionUnorderedList={setSelectionUnorderedList} /> ( +const PanelTabBar = ({ + screenIndex, + handleChange, + setSelectionBold, + setSelectionCode, + setSelectionItalic, + setSelectionLink, + setSelectionQuote, + setSelectionSize, + setSelectionUnorderedList, +}) => (
( {screenIndex === 0 && ( - + - + - + - + - + - +