0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-30 19:42:43 +00:00

Jump based on scroll position, not cursor position

This commit is contained in:
Trevor Buckner
2024-09-10 01:11:28 -04:00
parent ec74b994d7
commit 45a9501459
2 changed files with 12 additions and 4 deletions

View File

@@ -158,7 +158,7 @@ const Editor = createClass({
if(!this.props.liveScroll) return;
console.log("handleSourceScroll")
scrollingJump = true;
this.brewJump();
this.brewJump(this.getCurrentPage(false));
scrollingJump = false;
},
@@ -184,8 +184,13 @@ const Editor = createClass({
}); //TODO: not sure if updateeditorsize needed
},
getCurrentPage : function(){
const lines = this.props.brew.text.split('\n').slice(0, this.codeEditor.current.getCursorPosition().line + 1);
getCurrentPage : function(atCursor = true){
let lines = this.props.brew.text.split('\n');
if (atCursor)
lines = lines.slice(0, this.codeEditor.current.getCursorPosition().line + 1); // get cursor page
else
lines = lines.slice(0, this.codeEditor.current.getViewport().from + 1); // get view page
return _.reduce(lines, (r, line)=>{
if(
(this.props.renderer == 'legacy' && line.indexOf('\\page') !== -1)
@@ -357,7 +362,7 @@ const Editor = createClass({
},
brewJump : function(targetPage=this.getCurrentPage()){
console.log('jumpbrew')
console.log(`jumpBrew to page ${targetPage}`)
if(lockBrewJump) return;
if(!window) return;
lockSourceJump = true;

View File

@@ -399,6 +399,9 @@ const CodeEditor = createClass({
getCursorPosition : function(){
return this.codeMirror.getCursor();
},
getViewport : function(){
return this.codeMirror.getViewport();
},
updateSize : function(){
this.codeMirror.refresh();
},