0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-05-07 18:48:39 +00:00

Merge branch 'master' of https://github.com/naturalcrit/homebrewery into update-Codemirror

This commit is contained in:
Víctor Losada Hernández
2026-04-06 19:21:46 +02:00
21 changed files with 157 additions and 376 deletions
+29 -3
View File
@@ -266,6 +266,29 @@ const Editor = createReactClass({
this.forceUpdate();
},
//temporary fix until cm6 comes next update
attachCodeMirrorListeners : function(cm) {
if(!cm) return;
// detach previous (important on remount / view switch)
if(this._cm) {
this._cm.off('cursorActivity', this._onCursor);
this._cm.off('scroll', this._onScroll);
}
this._cm = cm;
this._onCursor = ()=>{
this.updateCurrentCursorPage(cm.getCursor());
};
this._onScroll = _.throttle(()=>{
const topLine = cm.lineAtHeight(cm.getScrollInfo().top, 'local');
this.updateCurrentViewPage(topLine);
}, 200);
cm.on('cursorActivity', this._onCursor);
cm.on('scroll', this._onScroll);
},
renderEditor : function(){
if(this.isText()){
return <>
@@ -281,7 +304,8 @@ const Editor = createReactClass({
editorTheme={this.state.editorTheme}
renderer={this.props.brew.renderer}
rerenderParent={this.rerenderParent}
style={{ height: `calc(100% - ${this.state.snippetBarHeight}px)` }} />
style={{ height: `calc(100% - ${this.state.snippetBarHeight}px)` }}
onReady={this.attachCodeMirrorListeners}/>
</>;
}
if(this.isStyle()){
@@ -297,7 +321,8 @@ const Editor = createReactClass({
editorTheme={this.state.editorTheme}
renderer={this.props.brew.renderer}
rerenderParent={this.rerenderParent}
style={{ height: `calc(100% - ${this.state.snippetBarHeight}px)` }} />
style={{ height: `calc(100% - ${this.state.snippetBarHeight}px)` }}
onReady={this.attachCodeMirrorListeners}/>
</>;
}
if(this.isMeta()){
@@ -328,7 +353,8 @@ const Editor = createReactClass({
editorTheme={this.state.editorTheme}
renderer={this.props.brew.renderer}
rerenderParent={this.rerenderParent}
style={{ height: `calc(100% - 25px)` }} />
style={{ height: `calc(100% - 25px)` }}
onReady={this.attachCodeMirrorListeners}/>
</>;
}
},