Steve Ruiz 2024-04-14 20:00:40 +01:00
rodzic 41601ac61e
commit a8af549130
2 zmienionych plików z 23 dodań i 11 usunięć

Wyświetl plik

@ -387,25 +387,38 @@ function ShapesWithSVGs() {
</>
)
}
function ReflowIfNeeded() {
const editor = useEditor()
const culledShapesRef = useRef<Set<TLShapeId>>(new Set())
useQuickReactor(
'reflow for culled shapes',
() => {
if (!editor.environment.isSafari) return
const culledShapes = editor.getCulledShapes()
if (
culledShapesRef.current.size === culledShapes.size &&
[...culledShapes].every((id) => culledShapesRef.current.has(id))
)
return
const prev = culledShapesRef.current
let reflow = false
if (prev.size !== culledShapes.size) {
reflow = true
} else {
for (const id of culledShapes) {
if (!prev.has(id)) {
reflow = true
break
}
}
}
if (reflow) {
const canvas = document.getElementsByClassName('tl-canvas')
if (canvas.length === 0) {
return
} // This causes a reflow
// https://gist.github.com/paulirish/5d52fb081b3570c81e3a
;(canvas[0] as HTMLDivElement).offsetHeight
}
culledShapesRef.current = culledShapes
const canvas = document.getElementsByClassName('tl-canvas')
if (canvas.length === 0) return
// This causes a reflow
// https://gist.github.com/paulirish/5d52fb081b3570c81e3a
const _height = (canvas[0] as HTMLDivElement).offsetHeight
},
[editor]
)

Wyświetl plik

@ -4226,8 +4226,7 @@ export class Editor extends EventEmitter<TLEventMap> {
*
* @public
*/
@computed
getCulledShapes() {
@computed getCulledShapes() {
const notVisibleShapes = this._notVisibleShapes().get()
const selectedShapeIds = this.getSelectedShapeIds()
const editingId = this.getEditingShapeId()