mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-11 13:22:39 +00:00
Clean up unused code
This commit is contained in:
@@ -3,7 +3,6 @@ require('./editor.less');
|
|||||||
const React = require('react');
|
const React = require('react');
|
||||||
const createClass = require('create-react-class');
|
const createClass = require('create-react-class');
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const cx = require('classnames');
|
|
||||||
const dedent = require('dedent-tabs').default;
|
const dedent = require('dedent-tabs').default;
|
||||||
const Markdown = require('../../../shared/naturalcrit/markdown.js');
|
const Markdown = require('../../../shared/naturalcrit/markdown.js');
|
||||||
|
|
||||||
@@ -22,20 +21,8 @@ const DEFAULT_STYLE_TEXT = dedent`
|
|||||||
color: black;
|
color: black;
|
||||||
}`;
|
}`;
|
||||||
|
|
||||||
let lastPage = 0;
|
|
||||||
let isJumping = false;
|
let isJumping = false;
|
||||||
|
|
||||||
const isElementCodeMirror=(element)=>{
|
|
||||||
let el = element;
|
|
||||||
while( el.tagName != 'body' ) {
|
|
||||||
if ( !el?.classList ) return false
|
|
||||||
if( el?.classList?.contains('CodeMirror-code') || el.classList.contains('CodeMirror-line'))
|
|
||||||
return true;
|
|
||||||
el = el.parentNode;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
const Editor = createClass({
|
const Editor = createClass({
|
||||||
displayName : 'Editor',
|
displayName : 'Editor',
|
||||||
getDefaultProps : function() {
|
getDefaultProps : function() {
|
||||||
@@ -56,9 +43,9 @@ const Editor = createClass({
|
|||||||
editorTheme : 'default',
|
editorTheme : 'default',
|
||||||
renderer : 'legacy',
|
renderer : 'legacy',
|
||||||
|
|
||||||
currentEditorCursorPageNum : 0,
|
currentEditorCursorPageNum : 1,
|
||||||
currentEditorViewPageNum : 0,
|
currentEditorViewPageNum : 1,
|
||||||
currentBrewRendererPageNum : 0,
|
currentBrewRendererPageNum : 1,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
getInitialState : function() {
|
getInitialState : function() {
|
||||||
@@ -85,15 +72,6 @@ const Editor = createClass({
|
|||||||
|
|
||||||
this.codeEditor.current.codeMirror.on('cursorActivity', (cm)=>{this.updateCurrentCursorPage(cm.getCursor())});
|
this.codeEditor.current.codeMirror.on('cursorActivity', (cm)=>{this.updateCurrentCursorPage(cm.getCursor())});
|
||||||
this.codeEditor.current.codeMirror.on('scroll', _.throttle(()=>{this.updateCurrentViewPage(this.codeEditor.current.getTopVisibleLine())}, 200));
|
this.codeEditor.current.codeMirror.on('scroll', _.throttle(()=>{this.updateCurrentViewPage(this.codeEditor.current.getTopVisibleLine())}, 200));
|
||||||
document.addEventListener('click', (e)=>{
|
|
||||||
if(isElementCodeMirror(e.target) && this.props.liveScroll ) {
|
|
||||||
const curPage = this.getCurrentPage();
|
|
||||||
if( curPage != lastPage ) {
|
|
||||||
this.brewJump();
|
|
||||||
lastPage = curPage;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const editorTheme = window.localStorage.getItem(EDITOR_THEME_KEY);
|
const editorTheme = window.localStorage.getItem(EDITOR_THEME_KEY);
|
||||||
if(editorTheme) {
|
if(editorTheme) {
|
||||||
@@ -132,33 +110,12 @@ const Editor = createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
handleControlKeys : function(e){
|
handleControlKeys : function(e){
|
||||||
const END_KEY = 35;
|
if(!(e.ctrlKey && e.metaKey && e.shiftKey)) return;
|
||||||
const HOME_KEY = 36;
|
|
||||||
const LEFTARROW_KEY = 37;
|
const LEFTARROW_KEY = 37;
|
||||||
const RIGHTARROW_KEY = 39;
|
const RIGHTARROW_KEY = 39;
|
||||||
|
if (e.keyCode == RIGHTARROW_KEY) this.brewJump();
|
||||||
if(this.props.liveScroll) {
|
if (e.keyCode == LEFTARROW_KEY) this.sourceJump();
|
||||||
//console.log('Should be scrollig!');
|
if (e.keyCode == LEFTARROW_KEY || e.keyCode == RIGHTARROW_KEY) {
|
||||||
//const movementKeys = [13, 33, 34, LEFTARROW_KEY, 38, RIGHTARROW_KEY, 40];
|
|
||||||
// if(movementKeys.includes(e.keyCode)) {
|
|
||||||
// const curPage = this.getCurrentPage();
|
|
||||||
// if(curPage != lastPage) {
|
|
||||||
// this.brewJump();
|
|
||||||
// lastPage = curPage;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!(e.ctrlKey && e.metaKey)) return;
|
|
||||||
|
|
||||||
if(!e.ctrlKey) return;
|
|
||||||
|
|
||||||
// Handle CTRL-HOME and CTRL-END
|
|
||||||
//if(((e.keyCode == END_KEY) || (e.keyCode == HOME_KEY)) && this.props.liveScroll) this.brewJump();
|
|
||||||
if(!e.metaKey) return;
|
|
||||||
//if(e.shiftKey && (e.keyCode == RIGHTARROW_KEY)) this.brewJump();
|
|
||||||
//if(e.shiftKey && (e.keyCode == LEFTARROW_KEY)) this.sourceJump();
|
|
||||||
if((e.keyCode == LEFTARROW_KEY) || (e.keyCode == RIGHTARROW_KEY)) {
|
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,9 +55,9 @@ const EditPage = createClass({
|
|||||||
autoSave : true,
|
autoSave : true,
|
||||||
autoSaveWarning : false,
|
autoSaveWarning : false,
|
||||||
unsavedTime : new Date(),
|
unsavedTime : new Date(),
|
||||||
currentEditorViewPageNum : 0,
|
currentEditorViewPageNum : 1,
|
||||||
currentEditorCursorPageNum : 0,
|
currentEditorCursorPageNum : 1,
|
||||||
currentBrewRendererPageNum : 0,
|
currentBrewRendererPageNum : 1,
|
||||||
displayLockMessage : this.props.brew.lock || false,
|
displayLockMessage : this.props.brew.lock || false,
|
||||||
themeBundle : {}
|
themeBundle : {}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -34,9 +34,9 @@ const HomePage = createClass({
|
|||||||
brew : this.props.brew,
|
brew : this.props.brew,
|
||||||
welcomeText : this.props.brew.text,
|
welcomeText : this.props.brew.text,
|
||||||
error : undefined,
|
error : undefined,
|
||||||
currentEditorViewPageNum : 0,
|
currentEditorViewPageNum : 1,
|
||||||
currentEditorCursorPageNum : 0,
|
currentEditorCursorPageNum : 1,
|
||||||
currentBrewRendererPageNum : 0,
|
currentBrewRendererPageNum : 1,
|
||||||
themeBundle : {}
|
themeBundle : {}
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -44,9 +44,9 @@ const NewPage = createClass({
|
|||||||
saveGoogle : (global.account && global.account.googleId ? true : false),
|
saveGoogle : (global.account && global.account.googleId ? true : false),
|
||||||
error : null,
|
error : null,
|
||||||
htmlErrors : Markdown.validate(brew.text),
|
htmlErrors : Markdown.validate(brew.text),
|
||||||
currentEditorViewPageNum : 0,
|
currentEditorViewPageNum : 1,
|
||||||
currentEditorCursorPageNum : 0,
|
currentEditorCursorPageNum : 1,
|
||||||
currentBrewRendererPageNum : 0,
|
currentBrewRendererPageNum : 1,
|
||||||
themeBundle : {}
|
themeBundle : {}
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user