0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-24 18:32:41 +00:00

Merge pull request #1701 from G-Ambatte/addEditorBar

Editor Toolbar - Undo and Redo.
This commit is contained in:
Trevor Buckner
2021-10-18 15:18:20 -04:00
committed by GitHub
5 changed files with 83 additions and 10 deletions

View File

@@ -1,3 +1,4 @@
/*eslint max-lines: ["warn", {"max": 300, "skipBlankLines": true, "skipComments": true}]*/
require('./editor.less');
const React = require('react');
const createClass = require('create-react-class');
@@ -198,6 +199,18 @@ const Editor = createClass({
}
},
redo : function(){
return this.refs.codeEditor?.redo();
},
historySize : function(){
return this.refs.codeEditor?.historySize();
},
undo : function(){
return this.refs.codeEditor?.undo();
},
render : function(){
this.highlightCustomMarkdown();
return (
@@ -208,7 +221,10 @@ const Editor = createClass({
onViewChange={this.handleViewChange}
onInject={this.handleInject}
showEditButtons={this.props.showEditButtons}
renderer={this.props.renderer} />
renderer={this.props.renderer}
undo={this.undo}
redo={this.redo}
historySize={this.historySize} />
{this.renderEditor()}
</div>

View File

@@ -50,4 +50,16 @@
.tooltipLeft("Jump to brew page");
}
.editorToolbar{
position: absolute;
top: 5px;
left: 50%;
color: black;
font-size: 13px;
z-index: 9;
span {
padding: 2px 5px;
}
}
}

View File

@@ -22,7 +22,10 @@ const Snippetbar = createClass({
onInject : ()=>{},
onToggle : ()=>{},
showEditButtons : true,
renderer : 'legacy'
renderer : 'legacy',
undo : ()=>{},
redo : ()=>{},
historySize : ()=>{}
};
},
@@ -60,6 +63,15 @@ const Snippetbar = createClass({
if(!this.props.showEditButtons) return;
return <div className='editors'>
<div className={`editorTool undo ${this.props.historySize()?.undo ? 'active' : ''}`}
onClick={this.props.undo} >
<i className='fas fa-undo' />
</div>
<div className={`editorTool redo ${this.props.historySize()?.redo ? 'active' : ''}`}
onClick={this.props.redo} >
<i className='fas fa-redo' />
</div>
<div className='divider'></div>
<div className={cx('text', { selected: this.props.view === 'text' })}
onClick={()=>this.props.onViewChange('text')}>
<i className='fa fa-beer' />

View File

@@ -10,7 +10,7 @@
top : 0px;
right : 0px;
height : @menuHeight;
width : 90px;
width : 125px;
justify-content : space-between;
&>div{
height : @menuHeight;
@@ -30,6 +30,29 @@
&.meta{
.tooltipLeft('Properties');
}
&.undo{
.tooltipLeft('Undo');
font-size : 0.75em;
color : grey;
&.active{
color : black;
}
}
&.redo{
.tooltipLeft('Redo');
font-size : 0.75em;
color : grey;
&.active{
color : black;
}
}
&.divider {
background: linear-gradient(#000, #000) no-repeat center/1px 100%;
width: 5px;
&:hover{
background-color: inherit;
}
}
}
}
.snippetBarButton{

View File

@@ -40,13 +40,14 @@ const CodeEditor = createClass({
buildEditor : function() {
this.codeMirror = CodeMirror(this.refs.editor, {
value : this.props.value,
lineNumbers : true,
lineWrapping : this.props.wrap,
mode : this.props.language, //TODO: CSS MODE DOESN'T SEEM TO LOAD PROPERLY
indentWithTabs : true,
tabSize : 2,
extraKeys : {
value : this.props.value,
lineNumbers : true,
lineWrapping : this.props.wrap,
mode : this.props.language, //TODO: CSS MODE DOESN'T SEEM TO LOAD PROPERLY
indentWithTabs : true,
tabSize : 2,
historyEventDelay : 250,
extraKeys : {
'Ctrl-B' : this.makeBold,
'Cmd-B' : this.makeBold,
'Ctrl-I' : this.makeItalic,
@@ -112,6 +113,15 @@ const CodeEditor = createClass({
updateSize : function(){
this.codeMirror.refresh();
},
redo : function(){
return this.codeMirror.redo();
},
undo : function(){
return this.codeMirror.undo();
},
historySize : function(){
return this.codeMirror.doc.historySize();
},
//----------------------//
render : function(){