mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Add button when scrolled outside of visible area (#643)
With the infinite scroll behavior, it's easy to scroll super far away from where the content is and have a hard time getting back. This PR adds a button to refocus on the center of the scene when no elements are visible anymore.
This commit is contained in:
parent
7c9e6dd3f1
commit
be97bd980e
8 changed files with 44 additions and 8 deletions
|
@ -32,7 +32,7 @@ export function renderScene(
|
|||
renderSelection?: boolean;
|
||||
} = {},
|
||||
) {
|
||||
if (!canvas) return;
|
||||
if (!canvas) return false;
|
||||
const context = canvas.getContext("2d")!;
|
||||
|
||||
const fillStyle = context.fillStyle;
|
||||
|
@ -57,6 +57,7 @@ export function renderScene(
|
|||
scrollY: typeof offsetY === "number" ? offsetY : sceneState.scrollY,
|
||||
};
|
||||
|
||||
let atLeastOneVisibleElement = false;
|
||||
elements.forEach(element => {
|
||||
if (
|
||||
!isVisibleElement(
|
||||
|
@ -71,6 +72,7 @@ export function renderScene(
|
|||
) {
|
||||
return;
|
||||
}
|
||||
atLeastOneVisibleElement = true;
|
||||
context.translate(
|
||||
element.x + sceneState.scrollX,
|
||||
element.y + sceneState.scrollY,
|
||||
|
@ -141,6 +143,8 @@ export function renderScene(
|
|||
context.strokeStyle = strokeStyle;
|
||||
context.fillStyle = fillStyle;
|
||||
}
|
||||
|
||||
return atLeastOneVisibleElement;
|
||||
}
|
||||
|
||||
function isVisibleElement(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue