0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-05-07 18:48:39 +00:00
This commit is contained in:
Víctor Losada Hernández
2026-04-13 01:29:14 +02:00
parent 95c0b409b9
commit 9dba69e8da
2 changed files with 15 additions and 8 deletions
+4 -3
View File
@@ -367,12 +367,13 @@ const CodeEditor = forwardRef(
const pos = pageBreaksRef.current[pageNumber - 1] ?? 0; const pos = pageBreaksRef.current[pageNumber - 1] ?? 0;
return pos; return pos;
}, },
setCursorToLine : (lineNumber)=>{ setCursorToPage : (pageNumber)=>{
const view = viewRef.current; const view = viewRef.current;
const line = view.state.doc.line(lineNumber); if(!view) return 0;
const pos = pageBreaksRef.current[pageNumber - 1] ?? 0;
view.dispatch({ view.dispatch({
selection : { anchor: line.from } selection : { anchor: pos }
}); });
view.focus(); view.focus();
+11 -5
View File
@@ -44,6 +44,7 @@ const DEFAULT_SNIPPET_TEXT = dedent`
This snippet is accessible in the brew tab, and will be inherited if the brew is used as a theme. This snippet is accessible in the brew tab, and will be inherited if the brew is used as a theme.
`; `;
let isJumping = false; let isJumping = false;
let jumpSource = null;
const Editor = createReactClass({ const Editor = createReactClass({
displayName : 'Editor', displayName : 'Editor',
@@ -164,7 +165,7 @@ const Editor = createReactClass({
}, },
brewJump : function(targetPage=this.props.currentEditorCursorPageNum, smooth=true){ brewJump : function(targetPage=this.props.currentEditorCursorPageNum, smooth=true){
if(!window || !this.isText() || isJumping) if(!window || !this.isText() || isJumping || jumpSource === 'source')
return; return;
// Get current brewRenderer scroll position and calculate target position // Get current brewRenderer scroll position and calculate target position
@@ -177,11 +178,13 @@ const Editor = createReactClass({
clearTimeout(scrollingTimeout); // Reset the timer every time a scroll event occurs clearTimeout(scrollingTimeout); // Reset the timer every time a scroll event occurs
scrollingTimeout = setTimeout(()=>{ scrollingTimeout = setTimeout(()=>{
isJumping = false; isJumping = false;
jumpSource = null;
brewRenderer.removeEventListener('scroll', checkIfScrollComplete); brewRenderer.removeEventListener('scroll', checkIfScrollComplete);
}, 150); // If 150 ms pass without a brewRenderer scroll event, assume scrolling is done }, 150); // If 150 ms pass without a brewRenderer scroll event, assume scrolling is done
}; };
isJumping = true; isJumping = true;
jumpSource = 'brew';
checkIfScrollComplete(); checkIfScrollComplete();
brewRenderer.addEventListener('scroll', checkIfScrollComplete); brewRenderer.addEventListener('scroll', checkIfScrollComplete);
@@ -205,17 +208,20 @@ const Editor = createReactClass({
}, },
sourceJump : function(targetPage=this.props.currentBrewRendererPageNum, smooth=true){ sourceJump : function(targetPage=this.props.currentBrewRendererPageNum, smooth=true){
if(!this.isText() || isJumping) if(!this.isText() || isJumping || jumpSource === 'brew')
return; return;
const editor = this.codeEditor.current; const editor = this.codeEditor.current;
if(!editor) return; if(!editor) return;
jumpSource = 'source';
editor.scrollToPage(targetPage); editor.scrollToPage(targetPage);
const pos = editor.getPagePos(targetPage); editor.setCursorToPage(targetPage);
editor.setCursorToPos?.(pos); setTimeout(()=>{
jumpSource = null;
}, 200);
}, },
//Called when there are changes to the editor's dimensions //Called when there are changes to the editor's dimensions
update : function(){}, update : function(){},