File tree 4 files changed +47
-1
lines changed
4 files changed +47
-1
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ import deepEqual from 'fast-deep-equal'
28
28
import { ContextMenu } from './ContextMenu'
29
29
import {
30
30
encodeHtml ,
31
+ isPrintableUnicode ,
31
32
parseTextHtmlData ,
32
33
parseTextPlainData ,
33
34
} from '../utils/copyPasting'
@@ -1456,7 +1457,7 @@ export const DataSheetGrid = React.memo(
1456
1457
)
1457
1458
event . preventDefault ( )
1458
1459
} else if (
1459
- ( event . key . match ( / ^ [ - ~ ] $ / ) || event . code . match ( / K e y [ A - Z \p { L } ] $ / u ) ) &&
1460
+ ( isPrintableUnicode ( event . key ) || event . code . match ( / K e y [ A - Z ] $ / ) ) &&
1460
1461
! event . ctrlKey &&
1461
1462
! event . metaKey &&
1462
1463
! event . altKey
Original file line number Diff line number Diff line change 2
2
parseTextPlainData ,
3
3
parseTextHtmlData ,
4
4
encodeHtml ,
5
+ isPrintableUnicode ,
5
6
} from './copyPasting'
6
7
import { JSDOM } from 'jsdom'
7
8
@@ -157,3 +158,23 @@ test('encodeHtml', () => {
157
158
'<div title="foo'bar">baz</div>'
158
159
)
159
160
} )
161
+
162
+ test ( 'isPrintableUnicode' , ( ) => {
163
+ expect ( isPrintableUnicode ( 'a' ) ) . toBe ( true )
164
+ expect ( isPrintableUnicode ( 'ş' ) ) . toBe ( true )
165
+ expect ( isPrintableUnicode ( 'Ğ' ) ) . toBe ( true )
166
+ expect ( isPrintableUnicode ( '中' ) ) . toBe ( true )
167
+ expect ( isPrintableUnicode ( '©' ) ) . toBe ( true )
168
+ expect ( isPrintableUnicode ( '5' ) ) . toBe ( true )
169
+ expect ( isPrintableUnicode ( '!' ) ) . toBe ( true )
170
+ expect ( isPrintableUnicode ( '.' ) ) . toBe ( true )
171
+ expect ( isPrintableUnicode ( ':' ) ) . toBe ( true )
172
+ expect ( isPrintableUnicode ( '[' ) ) . toBe ( true )
173
+ expect ( isPrintableUnicode ( '\x0B' ) ) . toBe ( false ) // Vertical Tab
174
+ expect ( isPrintableUnicode ( '\x7F' ) ) . toBe ( false ) // Delete
175
+ expect ( isPrintableUnicode ( '\r' ) ) . toBe ( false )
176
+ expect ( isPrintableUnicode ( ' ' ) ) . toBe ( false )
177
+ expect ( isPrintableUnicode ( '\t' ) ) . toBe ( false )
178
+ expect ( isPrintableUnicode ( '\n' ) ) . toBe ( false )
179
+ expect ( isPrintableUnicode ( '\x90' ) ) . toBe ( false ) // Non-printable character in the extended ASCII range
180
+ } )
Original file line number Diff line number Diff line change @@ -103,3 +103,7 @@ export const encodeHtml = (str: string) => {
103
103
. replace ( / " / g, '"' )
104
104
. replace ( / ' / g, ''' )
105
105
}
106
+
107
+ export const isPrintableUnicode = ( str : string ) : boolean => {
108
+ return str . match ( / ^ [ ^ \x00 - \x20 \x7F - \x9F ] $ / ) !== null
109
+ }
Original file line number Diff line number Diff line change @@ -116,6 +116,26 @@ test('Enter to edit', () => {
116
116
} )
117
117
} )
118
118
119
+ test ( 'Non-ascii character to edit' , ( ) => {
120
+ const ref = { current : null as unknown as DataSheetGridRef }
121
+ const data = {
122
+ current : [
123
+ { firstName : 'Elon' , lastName : 'Musk' } ,
124
+ { firstName : 'Jeff' , lastName : 'Bezos' } ,
125
+ ] ,
126
+ }
127
+
128
+ render ( < DataWrapper dataRef = { data } dsgRef = { ref } columns = { columns } /> )
129
+
130
+ act ( ( ) => ref . current . setActiveCell ( { col : 0 , row : 1 } ) )
131
+
132
+ userEvent . keyboard ( 'ş' )
133
+ expect ( data . current ) . toEqual ( [
134
+ { firstName : 'Elon' , lastName : 'Musk' } ,
135
+ { firstName : 'ş' , lastName : 'Bezos' } ,
136
+ ] )
137
+ } )
138
+
119
139
test ( 'Lazy cell validate with Enter' , ( ) => {
120
140
const ref = { current : null as unknown as DataSheetGridRef }
121
141
const data = {
You can’t perform that action at this time.
0 commit comments