fix: should not pasting html when shiftkey is down

pull/6345/head
Peng Xiao 2022-08-09 11:32:57 +08:00
parent 2308a5d120
commit cd1e8d88a9
4 changed files with 15 additions and 7 deletions

View File

@ -31,7 +31,7 @@ const getYoutubeId = (url: string) => {
export function usePaste(context: LogseqContextValue) {
const { handlers } = context
return React.useCallback<TLReactCallbacks<Shape>['onPaste']>(async (app, { point }) => {
return React.useCallback<TLReactCallbacks<Shape>['onPaste']>(async (app, { point, shiftKey }) => {
const assetId = uniqueId()
interface ImageAsset extends TLAsset {
size: number[]
@ -218,7 +218,7 @@ export function usePaste(context: LogseqContextValue) {
try {
let handled = await handleImage(item)
if (!handled) {
if (!handled && !shiftKey) {
handled = await handleHTML(item)
}

View File

@ -115,7 +115,11 @@ export class TLApp<
keys: 'mod+a',
fn: () => {
const { selectedTool } = this
if (selectedTool.currentState.id !== 'idle') return
if (
selectedTool.currentState.id !== 'idle' &&
!selectedTool.currentState.id.includes('hovering')
)
return
if (selectedTool.id !== 'select') {
this.selectTool('select')
}
@ -218,7 +222,7 @@ export class TLApp<
currentPageId: this.currentPageId,
selectedIds: Array.from(this.selectedIds.values()),
pages: Array.from(this.pages.values()).map(page => page.serialized),
assets: this.getCleanUpAssets()
assets: this.getCleanUpAssets(),
}
}
@ -376,10 +380,11 @@ export class TLApp<
}
}
paste = (e?: ClipboardEvent) => {
paste = (e?: ClipboardEvent, shiftKey?: boolean) => {
if (!this.editingShape) {
this.notify('paste', {
point: this.inputs.currentPoint,
shiftKey: !!shiftKey,
})
}
}

View File

@ -158,7 +158,7 @@ export type TLSubscriptionEvent =
}
| {
event: 'paste'
info: { point: number[] }
info: { point: number[]; shiftKey: boolean }
}
| {
event: 'create-assets'

View File

@ -6,20 +6,23 @@ import type { TLReactCustomEvents } from '~types'
export function useKeyboardEvents(ref: React.RefObject<HTMLDivElement>) {
const app = useApp()
const { callbacks } = useRendererContext()
const shiftKeyDownRef = React.useRef(false)
React.useEffect(() => {
const onKeyDown: TLReactCustomEvents['keyboard'] = e => {
callbacks.onKeyDown?.({ type: TLTargetType.Canvas, order: -1 }, e)
shiftKeyDownRef.current = e.shiftKey
}
const onKeyUp: TLReactCustomEvents['keyboard'] = e => {
callbacks.onKeyUp?.({ type: TLTargetType.Canvas, order: -1 }, e)
shiftKeyDownRef.current = e.shiftKey
}
const onPaste = (e: ClipboardEvent) => {
if (!app.editingShape && ref.current?.contains(document.activeElement)) {
e.preventDefault()
app.paste(e)
app.paste(e, shiftKeyDownRef.current)
}
}