fix(client): fix special white space happens when paste content (#5497)

This commit is contained in:
Junyi 2024-10-23 21:00:38 +08:00 committed by GitHub
parent 4203b7c7d5
commit 4a6bf09737
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 5 deletions

View File

@ -210,7 +210,7 @@ function getCurrentRange(element: HTMLElement): RangeIndexes {
export function TextArea(props) { export function TextArea(props) {
const { wrapSSR, hashId, componentCls } = useStyles(); const { wrapSSR, hashId, componentCls } = useStyles();
const { value = '', scope, onChange, multiline = true, changeOnSelect, style } = props; const { value = '', scope, onChange, changeOnSelect, style } = props;
const inputRef = useRef<HTMLDivElement>(null); const inputRef = useRef<HTMLDivElement>(null);
const [options, setOptions] = useState([]); const [options, setOptions] = useState([]);
const form = useForm(); const form = useForm();
@ -420,9 +420,10 @@ export function TextArea(props) {
hashId, hashId,
'ant-input', 'ant-input',
{ 'ant-input-disabled': disabled }, { 'ant-input-disabled': disabled },
// NOTE: `pre-wrap` here for avoid the `&nbsp;` (\x160) issue when paste content, we need normal space (\x32).
css` css`
overflow: auto; overflow: auto;
white-space: ${multiline ? 'normal' : 'nowrap'}; white-space: pre-wrap;
&[placeholder]:empty::before { &[placeholder]:empty::before {
content: attr(placeholder); content: attr(placeholder);

View File

@ -25,8 +25,8 @@ export type RequestConfig = Pick<AxiosRequestConfig, 'url' | 'method' | 'params'
}; };
const ContentTypeTransformers = { const ContentTypeTransformers = {
'application/json'(data) { 'text/plain'(data) {
return data; return data.toString();
}, },
'application/x-www-form-urlencoded'(data: { name: string; value: string }[]) { 'application/x-www-form-urlencoded'(data: { name: string; value: string }[]) {
return new URLSearchParams( return new URLSearchParams(
@ -52,6 +52,7 @@ async function request(config) {
// TODO(feat): only support JSON type for now, should support others in future // TODO(feat): only support JSON type for now, should support others in future
headers['Content-Type'] = contentType; headers['Content-Type'] = contentType;
const transformer = ContentTypeTransformers[contentType];
return axios.request({ return axios.request({
url: trim(url), url: trim(url),
@ -61,7 +62,7 @@ async function request(config) {
timeout, timeout,
...(method.toLowerCase() !== 'get' && data != null ...(method.toLowerCase() !== 'get' && data != null
? { ? {
data: ContentTypeTransformers[contentType](data), data: transformer ? transformer(data) : data,
} }
: {}), : {}),
}); });