From e9d71cc217cd657bad1129365cf5caf27b56456f Mon Sep 17 00:00:00 2001 From: Peng Xiao Date: Thu, 1 Sep 2022 16:40:24 +0800 Subject: [PATCH] fix: do not deselect shapes --- tldraw/demo/src/App.jsx | 2 +- tldraw/demo/vite.config.js | 10 ---------- tldraw/packages/core/src/lib/TLHistory.ts | 7 +++---- tldraw/packages/core/src/lib/TLPage/TLPage.ts | 1 + tldraw/packages/core/src/utils/index.ts | 4 ++++ 5 files changed, 9 insertions(+), 15 deletions(-) diff --git a/tldraw/demo/src/App.jsx b/tldraw/demo/src/App.jsx index 241efd352..9fb29e8af 100644 --- a/tldraw/demo/src/App.jsx +++ b/tldraw/demo/src/App.jsx @@ -145,7 +145,7 @@ export default function App() { React.useEffect(() => { const interval = setInterval(() => { setModel(onLoad()) - }, 5000) + }, 2000) return () => { clearInterval(interval) diff --git a/tldraw/demo/vite.config.js b/tldraw/demo/vite.config.js index d8ba19056..521752635 100644 --- a/tldraw/demo/vite.config.js +++ b/tldraw/demo/vite.config.js @@ -33,16 +33,6 @@ export default defineConfig({ find: 'tldraw-logseq', replacement: bases.tldrawLogseq, }, - { - find: /~(.*)/, - replacement: '$1', - customResolver: (id, importer) => { - if (id) { - const base = Object.values(bases).find(value => importer.startsWith(value)) - return base ? path.join('/@fs', base, id) : null - } - }, - }, { find: '@tldraw/core', replacement: bases.core, diff --git a/tldraw/packages/core/src/lib/TLHistory.ts b/tldraw/packages/core/src/lib/TLHistory.ts index 93521354f..287b60eb2 100644 --- a/tldraw/packages/core/src/lib/TLHistory.ts +++ b/tldraw/packages/core/src/lib/TLHistory.ts @@ -1,6 +1,6 @@ import { computed, makeObservable, transaction } from 'mobx' import type { TLEventMap } from '../types' -import { deepEqual } from '../utils' +import { dedupe, deepEqual } from '../utils' import type { TLShape } from './shapes' import type { TLApp, TLDocumentModel } from './TLApp' import { TLPage } from './TLPage' @@ -94,12 +94,11 @@ export class TLHistory { transaction(() => { - const { currentPageId, selectedIds, pages } = snapshot + const { selectedIds, pages } = snapshot const wasPaused = this.isPaused this.pause() - const newSelectedIds = - selectedIds.length === 0 ? Array.from(this.app.selectedIds) : selectedIds + const newSelectedIds = dedupe([...this.app.selectedIds, ...selectedIds]) try { const pagesMap = new Map(this.app.pages) diff --git a/tldraw/packages/core/src/lib/TLPage/TLPage.ts b/tldraw/packages/core/src/lib/TLPage/TLPage.ts index 94b6875a7..20071a663 100644 --- a/tldraw/packages/core/src/lib/TLPage/TLPage.ts +++ b/tldraw/packages/core/src/lib/TLPage/TLPage.ts @@ -70,6 +70,7 @@ export class TLPage toJS(s)), bindings: deepCopy(this.bindings), nonce: this.nonce, + selectedIds: deepCopy(this.app.selectedIds), } } diff --git a/tldraw/packages/core/src/utils/index.ts b/tldraw/packages/core/src/utils/index.ts index 619d6d00a..cf6a0e50a 100644 --- a/tldraw/packages/core/src/utils/index.ts +++ b/tldraw/packages/core/src/utils/index.ts @@ -58,6 +58,10 @@ export function debounce void>( } } +export function dedupe(arr: T[]) { + return [...new Set(arr)] +} + /** Linear interpolate between two values. */ export function lerp(a: number, b: number, t: number) { return a + (b - a) * t