mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-16 21:12:49 +00:00
Jump based on scroll position, not cursor position
This commit is contained in:
@@ -158,7 +158,7 @@ const Editor = createClass({
|
|||||||
if(!this.props.liveScroll) return;
|
if(!this.props.liveScroll) return;
|
||||||
console.log("handleSourceScroll")
|
console.log("handleSourceScroll")
|
||||||
scrollingJump = true;
|
scrollingJump = true;
|
||||||
this.brewJump();
|
this.brewJump(this.getCurrentPage(false));
|
||||||
scrollingJump = false;
|
scrollingJump = false;
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -184,8 +184,13 @@ const Editor = createClass({
|
|||||||
}); //TODO: not sure if updateeditorsize needed
|
}); //TODO: not sure if updateeditorsize needed
|
||||||
},
|
},
|
||||||
|
|
||||||
getCurrentPage : function(){
|
getCurrentPage : function(atCursor = true){
|
||||||
const lines = this.props.brew.text.split('\n').slice(0, this.codeEditor.current.getCursorPosition().line + 1);
|
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)=>{
|
return _.reduce(lines, (r, line)=>{
|
||||||
if(
|
if(
|
||||||
(this.props.renderer == 'legacy' && line.indexOf('\\page') !== -1)
|
(this.props.renderer == 'legacy' && line.indexOf('\\page') !== -1)
|
||||||
@@ -357,7 +362,7 @@ const Editor = createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
brewJump : function(targetPage=this.getCurrentPage()){
|
brewJump : function(targetPage=this.getCurrentPage()){
|
||||||
console.log('jumpbrew')
|
console.log(`jumpBrew to page ${targetPage}`)
|
||||||
if(lockBrewJump) return;
|
if(lockBrewJump) return;
|
||||||
if(!window) return;
|
if(!window) return;
|
||||||
lockSourceJump = true;
|
lockSourceJump = true;
|
||||||
|
|||||||
@@ -399,6 +399,9 @@ const CodeEditor = createClass({
|
|||||||
getCursorPosition : function(){
|
getCursorPosition : function(){
|
||||||
return this.codeMirror.getCursor();
|
return this.codeMirror.getCursor();
|
||||||
},
|
},
|
||||||
|
getViewport : function(){
|
||||||
|
return this.codeMirror.getViewport();
|
||||||
|
},
|
||||||
updateSize : function(){
|
updateSize : function(){
|
||||||
this.codeMirror.refresh();
|
this.codeMirror.refresh();
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user