浏览代码

Restores more simple text

main
Steve Ruiz 4 年前
父节点
当前提交
3f35d2a245
共有 1 个文件被更改,包括 21 次插入46 次删除
  1. 21
    46
      lib/shape-utils/text.tsx

+ 21
- 46
lib/shape-utils/text.tsx 查看文件

@@ -1,15 +1,13 @@
1 1
 import { uniqueId } from 'utils/utils'
2
+import vec from 'utils/vec'
2 3
 import { TextShape, ShapeType, FontSize } from 'types'
3 4
 import { registerShapeUtils } from './index'
4
-import {
5
-  defaultStyle,
6
-  getFontSize,
7
-  getFontStyle,
8
-  getShapeStyle,
9
-} from 'lib/shape-styles'
5
+import { defaultStyle, getFontStyle, getShapeStyle } from 'lib/shape-styles'
10 6
 import styled from 'styles'
11 7
 import state from 'state'
12
-import React from 'react'
8
+import { useEffect, useRef } from 'react'
9
+
10
+// A div used for measurement
13 11
 
14 12
 if (document.getElementById('__textMeasure')) {
15 13
   document.getElementById('__textMeasure').remove()
@@ -18,18 +16,22 @@ if (document.getElementById('__textMeasure')) {
18 16
 // A div used for measurement
19 17
 const mdiv = document.createElement('pre')
20 18
 mdiv.id = '__textMeasure'
21
-mdiv.style.whiteSpace = 'pre'
22
-mdiv.style.width = 'auto'
23
-mdiv.style.border = '1px solid red'
24
-mdiv.style.padding = '4px'
25
-mdiv.style.margin = '0px'
26
-mdiv.style.opacity = '0'
27
-mdiv.style.position = 'absolute'
28
-mdiv.style.top = '-500px'
29
-mdiv.style.left = '0px'
30
-mdiv.style.zIndex = '9999'
19
+
20
+Object.assign(mdiv.style, {
21
+  whiteSpace: 'pre',
22
+  width: 'auto',
23
+  border: '1px solid red',
24
+  padding: '4px',
25
+  margin: '0px',
26
+  opacity: '0',
27
+  position: 'absolute',
28
+  top: '-500px',
29
+  left: '0px',
30
+  zIndex: '9999',
31
+})
32
+
31 33
 mdiv.tabIndex = -1
32
-mdiv.setAttribute('readonly', 'true')
34
+
33 35
 document.body.appendChild(mdiv)
34 36
 
35 37
 function normalizeText(text: string) {
@@ -95,29 +97,6 @@ const text = registerShapeUtils<TextShape>({
95 97
       state.send('FOCUSED_EDITING_SHAPE')
96 98
     }
97 99
 
98
-    const lineHeight = getFontSize(shape.fontSize) * shape.scale
99
-    const gap = lineHeight * 0.4
100
-
101
-    if (!isEditing) {
102
-      return (
103
-        <g id={id} pointerEvents="none">
104
-          {text.split('\n').map((str, i) => (
105
-            <text
106
-              key={i}
107
-              x={4}
108
-              y={4 + gap / 2 + i * (lineHeight + gap)}
109
-              style={{ font }}
110
-              width={bounds.width}
111
-              height={bounds.height}
112
-              dominant-baseline="hanging"
113
-            >
114
-              {str}
115
-            </text>
116
-          ))}
117
-        </g>
118
-      )
119
-    }
120
-
121 100
     return (
122 101
       <foreignObject
123 102
         id={id}
@@ -134,17 +113,15 @@ const text = registerShapeUtils<TextShape>({
134 113
               font,
135 114
               color: styles.stroke,
136 115
             }}
137
-            tabIndex={0}
138 116
             value={text}
117
+            tabIndex={0}
139 118
             autoComplete="false"
140 119
             autoCapitalize="false"
141 120
             autoCorrect="false"
142
-            spellCheck="false"
143 121
             onFocus={handleFocus}
144 122
             onBlur={handleBlur}
145 123
             onKeyDown={handleKeyDown}
146 124
             onChange={handleChange}
147
-            dir="auto"
148 125
           />
149 126
         ) : (
150 127
           <StyledText
@@ -234,10 +211,8 @@ const StyledText = styled('div', {
234 211
   overflow: 'hidden',
235 212
   pointerEvents: 'none',
236 213
   userSelect: 'none',
237
-  backfaceVisibility: 'hidden',
238 214
   display: 'inline-block',
239 215
   position: 'relative',
240
-  zIndex: 0,
241 216
 })
242 217
 
243 218
 const StyledTextArea = styled('textarea', {

正在加载...
取消
保存