[fix] fix text shapes bugs (#509)
* cleanup * Fix text size, and slash * Remove console.log
This commit is contained in:
parent
bff8b3cc07
commit
08a930f59c
5 changed files with 10 additions and 11 deletions
|
@ -878,7 +878,11 @@ export class TLDR {
|
||||||
static fixNewLines = /\r?\n|\r/g
|
static fixNewLines = /\r?\n|\r/g
|
||||||
|
|
||||||
static normalizeText(text: string) {
|
static normalizeText(text: string) {
|
||||||
return text.replace(TLDR.fixNewLines, '\n')
|
return text
|
||||||
|
.replace(TLDR.fixNewLines, '\n')
|
||||||
|
.split('\n')
|
||||||
|
.map((x) => x || ' ')
|
||||||
|
.join('\n')
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------------- */
|
/* -------------------------------------------------- */
|
||||||
|
|
|
@ -2920,7 +2920,7 @@ export class TldrawApp extends StateManager<TDSnapshot> {
|
||||||
onKeyDown: TLKeyboardEventHandler = (key, info, e) => {
|
onKeyDown: TLKeyboardEventHandler = (key, info, e) => {
|
||||||
switch (e.key) {
|
switch (e.key) {
|
||||||
case '/': {
|
case '/': {
|
||||||
if (this.status === 'idle') {
|
if (this.status === 'idle' && !this.pageState.editingId) {
|
||||||
const { shiftKey, metaKey, altKey, ctrlKey, spaceKey } = this
|
const { shiftKey, metaKey, altKey, ctrlKey, spaceKey } = this
|
||||||
|
|
||||||
this.onPointerDown(
|
this.onPointerDown(
|
||||||
|
@ -3562,7 +3562,6 @@ export class TldrawApp extends StateManager<TDSnapshot> {
|
||||||
isZoomSnap: false,
|
isZoomSnap: false,
|
||||||
isFocusMode: false,
|
isFocusMode: false,
|
||||||
isSnapping: false,
|
isSnapping: false,
|
||||||
//@ts-ignore
|
|
||||||
isDebugMode: process.env.NODE_ENV === 'development',
|
isDebugMode: process.env.NODE_ENV === 'development',
|
||||||
isReadonlyMode: false,
|
isReadonlyMode: false,
|
||||||
nudgeDistanceLarge: 16,
|
nudgeDistanceLarge: 16,
|
||||||
|
|
|
@ -3,7 +3,6 @@ import * as React from 'react'
|
||||||
import { Utils, HTMLContainer, TLBounds } from '@tldraw/core'
|
import { Utils, HTMLContainer, TLBounds } from '@tldraw/core'
|
||||||
import { defaultTextStyle, getShapeStyle, getFontStyle } from '../shared/shape-styles'
|
import { defaultTextStyle, getShapeStyle, getFontStyle } from '../shared/shape-styles'
|
||||||
import { TextShape, TDMeta, TDShapeType, TransformInfo, AlignStyle } from '~types'
|
import { TextShape, TDMeta, TDShapeType, TransformInfo, AlignStyle } from '~types'
|
||||||
import { TextAreaUtils } from '../shared'
|
|
||||||
import { BINDING_DISTANCE, GHOSTED_OPACITY, LETTER_SPACING } from '~constants'
|
import { BINDING_DISTANCE, GHOSTED_OPACITY, LETTER_SPACING } from '~constants'
|
||||||
import { TDShapeUtil } from '../TDShapeUtil'
|
import { TDShapeUtil } from '../TDShapeUtil'
|
||||||
import { styled } from '~styles'
|
import { styled } from '~styles'
|
||||||
|
@ -219,7 +218,7 @@ export class TextUtil extends TDShapeUtil<T, E> {
|
||||||
return { minX: 0, minY: 0, maxX: 10, maxY: 10, width: 10, height: 10 }
|
return { minX: 0, minY: 0, maxX: 10, maxY: 10, width: 10, height: 10 }
|
||||||
}
|
}
|
||||||
|
|
||||||
melm.innerHTML = `${shape.text}‍`
|
melm.textContent = shape.text
|
||||||
melm.style.font = getFontStyle(shape.style)
|
melm.style.font = getFontStyle(shape.style)
|
||||||
|
|
||||||
// In tests, offsetWidth and offsetHeight will be 0
|
// In tests, offsetWidth and offsetHeight will be 0
|
||||||
|
@ -334,7 +333,7 @@ function getMeasurementDiv() {
|
||||||
border: '1px solid transparent',
|
border: '1px solid transparent',
|
||||||
padding: '4px',
|
padding: '4px',
|
||||||
margin: '0px',
|
margin: '0px',
|
||||||
letterSpacing: `${LETTER_SPACING}px`,
|
letterSpacing: LETTER_SPACING,
|
||||||
opacity: '0',
|
opacity: '0',
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
top: '-500px',
|
top: '-500px',
|
||||||
|
|
|
@ -16,7 +16,7 @@ function getMeasurementDiv() {
|
||||||
border: '1px solid transparent',
|
border: '1px solid transparent',
|
||||||
padding: '4px',
|
padding: '4px',
|
||||||
margin: '0px',
|
margin: '0px',
|
||||||
letterSpacing: `${LETTER_SPACING}px`,
|
letterSpacing: LETTER_SPACING,
|
||||||
opacity: '0',
|
opacity: '0',
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
top: '-500px',
|
top: '-500px',
|
||||||
|
@ -59,7 +59,7 @@ export function getTextLabelSize(text: string, font: string) {
|
||||||
prevText = text
|
prevText = text
|
||||||
prevFont = font
|
prevFont = font
|
||||||
|
|
||||||
melm.innerHTML = `${text}‍`
|
melm.textContent = `${text}`
|
||||||
melm.style.font = font
|
melm.style.font = font
|
||||||
|
|
||||||
// In tests, offsetWidth and offsetHeight will be 0
|
// In tests, offsetWidth and offsetHeight will be 0
|
||||||
|
|
|
@ -16,7 +16,6 @@ export function transformRectangle<T extends TLShape & { size: number[] }>(
|
||||||
const size = Vec.toFixed(
|
const size = Vec.toFixed(
|
||||||
Vec.mul(initialShape.size, Math.min(Math.abs(scaleX), Math.abs(scaleY)))
|
Vec.mul(initialShape.size, Math.min(Math.abs(scaleX), Math.abs(scaleY)))
|
||||||
)
|
)
|
||||||
|
|
||||||
const point = Vec.toFixed([
|
const point = Vec.toFixed([
|
||||||
bounds.minX +
|
bounds.minX +
|
||||||
(bounds.width - shape.size[0]) * (scaleX < 0 ? 1 - transformOrigin[0] : transformOrigin[0]),
|
(bounds.width - shape.size[0]) * (scaleX < 0 ? 1 - transformOrigin[0] : transformOrigin[0]),
|
||||||
|
@ -24,14 +23,12 @@ export function transformRectangle<T extends TLShape & { size: number[] }>(
|
||||||
(bounds.height - shape.size[1]) *
|
(bounds.height - shape.size[1]) *
|
||||||
(scaleY < 0 ? 1 - transformOrigin[1] : transformOrigin[1]),
|
(scaleY < 0 ? 1 - transformOrigin[1] : transformOrigin[1]),
|
||||||
])
|
])
|
||||||
|
|
||||||
const rotation =
|
const rotation =
|
||||||
(scaleX < 0 && scaleY >= 0) || (scaleY < 0 && scaleX >= 0)
|
(scaleX < 0 && scaleY >= 0) || (scaleY < 0 && scaleX >= 0)
|
||||||
? initialShape.rotation
|
? initialShape.rotation
|
||||||
? -initialShape.rotation
|
? -initialShape.rotation
|
||||||
: 0
|
: 0
|
||||||
: initialShape.rotation
|
: initialShape.rotation
|
||||||
|
|
||||||
return {
|
return {
|
||||||
size,
|
size,
|
||||||
point,
|
point,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue