0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-10 02:42:43 +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'); require('./editor.less');
const React = require('react'); const React = require('react');
const createClass = require('create-react-class'); 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(){ render : function(){
this.highlightCustomMarkdown(); this.highlightCustomMarkdown();
return ( return (
@@ -208,7 +221,10 @@ const Editor = createClass({
onViewChange={this.handleViewChange} onViewChange={this.handleViewChange}
onInject={this.handleInject} onInject={this.handleInject}
showEditButtons={this.props.showEditButtons} showEditButtons={this.props.showEditButtons}
renderer={this.props.renderer} /> renderer={this.props.renderer}
undo={this.undo}
redo={this.redo}
historySize={this.historySize} />
{this.renderEditor()} {this.renderEditor()}
</div> </div>

View File

@@ -50,4 +50,16 @@
.tooltipLeft("Jump to brew page"); .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 : ()=>{}, onInject : ()=>{},
onToggle : ()=>{}, onToggle : ()=>{},
showEditButtons : true, showEditButtons : true,
renderer : 'legacy' renderer : 'legacy',
undo : ()=>{},
redo : ()=>{},
historySize : ()=>{}
}; };
}, },
@@ -60,6 +63,15 @@ const Snippetbar = createClass({
if(!this.props.showEditButtons) return; if(!this.props.showEditButtons) return;
return <div className='editors'> 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' })} <div className={cx('text', { selected: this.props.view === 'text' })}
onClick={()=>this.props.onViewChange('text')}> onClick={()=>this.props.onViewChange('text')}>
<i className='fa fa-beer' /> <i className='fa fa-beer' />

View File

@@ -10,7 +10,7 @@
top : 0px; top : 0px;
right : 0px; right : 0px;
height : @menuHeight; height : @menuHeight;
width : 90px; width : 125px;
justify-content : space-between; justify-content : space-between;
&>div{ &>div{
height : @menuHeight; height : @menuHeight;
@@ -30,6 +30,29 @@
&.meta{ &.meta{
.tooltipLeft('Properties'); .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{ .snippetBarButton{

View File

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