Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/editor/api-report.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1328,6 +1328,7 @@ export class Editor extends EventEmitter<TLEventMap> {
getViewportPageBounds(): Box;
getViewportScreenBounds(): Box;
getViewportScreenCenter(): Vec;
getVisibleRenderingShapes(): TLRenderingShape[];
getZoomLevel(): number;
groupShapes(shapes: TLShape[], opts?: Partial<{
groupId: TLShapeId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,9 @@ function OverlaysWrapper() {
function ShapesWithSVGs() {
const editor = useEditor()

const renderingShapes = useValue('rendering shapes', () => editor.getRenderingShapes(), [editor])
const renderingShapes = useValue('rendering shapes', () => editor.getVisibleRenderingShapes(), [
editor,
])

return renderingShapes.map((result) => (
<Fragment key={result.id + '_fragment'}>
Expand Down Expand Up @@ -433,7 +435,9 @@ function ReflowIfNeeded() {
function ShapesToDisplay() {
const editor = useEditor()

const renderingShapes = useValue('rendering shapes', () => editor.getRenderingShapes(), [editor])
const renderingShapes = useValue('rendering shapes', () => editor.getVisibleRenderingShapes(), [
editor,
])

return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ export const DefaultShapeIndicators = memo(function DefaultShapeIndicators({
[editor]
)

// Show indicators only for the shapes that are currently being rendered (ie that are on screen)
const renderingShapes = useValue('rendering shapes', () => editor.getRenderingShapes(), [editor])
// Show indicators only for shapes that are currently visible.
const renderingShapes = useValue('rendering shapes', () => editor.getVisibleRenderingShapes(), [
editor,
])

const { ShapeIndicator } = useEditorComponents()
if (!ShapeIndicator) return null
Expand Down
10 changes: 10 additions & 0 deletions packages/editor/src/lib/editor/Editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4232,6 +4232,16 @@ export class Editor extends EventEmitter<TLEventMap> {
return renderingShapes.sort(sortById)
}

/**
* Get the rendering shapes that are currently visible in the viewport.
*
* @public
*/
@computed getVisibleRenderingShapes() {
const culledShapes = this.getCulledShapes()
return this.getRenderingShapes().filter(({ id }) => !culledShapes.has(id))
}

/* --------------------- Pages ---------------------- */

@computed private _getAllPagesQuery() {
Expand Down
Loading