fix: do not deselect shapes

pull/6570/head
Peng Xiao 2022-09-01 16:40:24 +08:00
parent 273c8563ed
commit e9d71cc217
5 changed files with 9 additions and 15 deletions

View File

@ -145,7 +145,7 @@ export default function App() {
React.useEffect(() => { React.useEffect(() => {
const interval = setInterval(() => { const interval = setInterval(() => {
setModel(onLoad()) setModel(onLoad())
}, 5000) }, 2000)
return () => { return () => {
clearInterval(interval) clearInterval(interval)

View File

@ -33,16 +33,6 @@ export default defineConfig({
find: 'tldraw-logseq', find: 'tldraw-logseq',
replacement: bases.tldrawLogseq, 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', find: '@tldraw/core',
replacement: bases.core, replacement: bases.core,

View File

@ -1,6 +1,6 @@
import { computed, makeObservable, transaction } from 'mobx' import { computed, makeObservable, transaction } from 'mobx'
import type { TLEventMap } from '../types' import type { TLEventMap } from '../types'
import { deepEqual } from '../utils' import { dedupe, deepEqual } from '../utils'
import type { TLShape } from './shapes' import type { TLShape } from './shapes'
import type { TLApp, TLDocumentModel } from './TLApp' import type { TLApp, TLDocumentModel } from './TLApp'
import { TLPage } from './TLPage' import { TLPage } from './TLPage'
@ -94,12 +94,11 @@ export class TLHistory<S extends TLShape = TLShape, K extends TLEventMap = TLEve
deserialize = (snapshot: TLDocumentModel) => { deserialize = (snapshot: TLDocumentModel) => {
transaction(() => { transaction(() => {
const { currentPageId, selectedIds, pages } = snapshot const { selectedIds, pages } = snapshot
const wasPaused = this.isPaused const wasPaused = this.isPaused
this.pause() this.pause()
const newSelectedIds = const newSelectedIds = dedupe([...this.app.selectedIds, ...selectedIds])
selectedIds.length === 0 ? Array.from(this.app.selectedIds) : selectedIds
try { try {
const pagesMap = new Map(this.app.pages) const pagesMap = new Map(this.app.pages)

View File

@ -70,6 +70,7 @@ export class TLPage<S extends TLShape = TLShape, E extends TLEventMap = TLEventM
.map(s => toJS(s)), .map(s => toJS(s)),
bindings: deepCopy(this.bindings), bindings: deepCopy(this.bindings),
nonce: this.nonce, nonce: this.nonce,
selectedIds: deepCopy(this.app.selectedIds),
} }
} }

View File

@ -58,6 +58,10 @@ export function debounce<T extends (...args: any[]) => void>(
} }
} }
export function dedupe<T>(arr: T[]) {
return [...new Set(arr)]
}
/** Linear interpolate between two values. */ /** Linear interpolate between two values. */
export function lerp(a: number, b: number, t: number) { export function lerp(a: number, b: number, t: number) {
return a + (b - a) * t return a + (b - a) * t