0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-23 14:23:21 +00:00

Compare commits

...

3 Commits

Author SHA1 Message Date
Trevor Buckner
0fd3448826 Fix check that editor is in Text tab 2024-10-15 08:01:41 -04:00
Trevor Buckner
3bd73417e6 Add optional chaining 2024-10-14 22:48:27 -04:00
Trevor Buckner
72b69ebb6a Memoize BrewRenderer
Only re-render BrewRenderer when specific props have changed.

Fixes lag during scrolling, which updates the "currentPage" prop, but isn't actually used until the text is changed.
2024-10-14 21:55:02 -04:00
2 changed files with 17 additions and 4 deletions

View File

@@ -1,7 +1,7 @@
/*eslint max-lines: ["warn", {"max": 300, "skipBlankLines": true, "skipComments": true}]*/ /*eslint max-lines: ["warn", {"max": 300, "skipBlankLines": true, "skipComments": true}]*/
require('./brewRenderer.less'); require('./brewRenderer.less');
const React = require('react'); const React = require('react');
const { useState, useRef, useCallback } = React; const { useState, useRef, useCallback, memo } = React;
const _ = require('lodash'); const _ = require('lodash');
const MarkdownLegacy = require('naturalcrit/markdownLegacy.js'); const MarkdownLegacy = require('naturalcrit/markdownLegacy.js');
@@ -47,7 +47,7 @@ const BrewPage = (props)=>{
const renderedPages = []; const renderedPages = [];
let rawPages = []; let rawPages = [];
const BrewRenderer = (props)=>{ const BrewRenderer = memo((props)=>{
props = { props = {
text : '', text : '',
style : '', style : '',
@@ -224,6 +224,19 @@ const BrewRenderer = (props)=>{
</Frame> </Frame>
</> </>
); );
}; }, arePropsEqual);
//Only re-render brewRenderer if arePropsEqual == true
function arePropsEqual(oldProps, newProps) {
return (
oldProps?.text?.length === newProps?.text?.length &&
oldProps?.style?.length === newProps?.style?.length &&
oldProps?.renderer === newProps?.renderer &&
oldProps?.theme === newProps?.theme &&
oldProps?.errors === newProps?.errors &&
oldProps?.themeBundle === newProps?.themeBundle &&
oldProps?.lang === newProps?.lang
);
}
module.exports = BrewRenderer; module.exports = BrewRenderer;

View File

@@ -355,7 +355,7 @@ const Editor = createClass({
}, },
sourceJump : function(targetPage=this.props.currentBrewRendererPageNum, smooth=true){ sourceJump : function(targetPage=this.props.currentBrewRendererPageNum, smooth=true){
if(!this.isText || isJumping) if(!this.isText() || isJumping)
return; return;
const textSplit = this.props.renderer == 'V3' ? /^\\page$/gm : /\\page/; const textSplit = this.props.renderer == 'V3' ? /^\\page$/gm : /\\page/;