tools edit modal => editing schema cause cursor goto end #4652

Closed
opened 2026-02-21 18:07:24 -05:00 by yindo · 1 comment
Owner

Originally created by @qweasdzxcpkh on GitHub (Jul 17, 2024).

Originally assigned to: @JzoNgKVO on GitHub.

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.6.14

Cloud or Self Hosted

Cloud, Self Hosted (Docker), Self Hosted (Source)

Steps to reproduce

check this video please.

https://github.com/user-attachments/assets/0febad04-d0aa-4eec-801a-68960d323697

✔️ Expected Behavior

Editing schema changes the current form context without moving my cursor to the end.

BTW, i fixed it in my localhost. please check my PR.

https://github.com/user-attachments/assets/10c1c9e8-e245-4d68-9619-505fd27cb933

Actual Behavior

Editing causes my cursor to move to the end. very bad experience

Originally created by @qweasdzxcpkh on GitHub (Jul 17, 2024). Originally assigned to: @JzoNgKVO on GitHub. ### Self Checks - [X] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [X] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [X] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [X] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [X] Please do not modify this template :) and fill in all the required fields. ### Dify version 0.6.14 ### Cloud or Self Hosted Cloud, Self Hosted (Docker), Self Hosted (Source) ### Steps to reproduce check this video please. https://github.com/user-attachments/assets/0febad04-d0aa-4eec-801a-68960d323697 ### ✔️ Expected Behavior Editing schema changes the current form context without moving my cursor to the end. BTW, i fixed it in my localhost. please check my PR. https://github.com/user-attachments/assets/10c1c9e8-e245-4d68-9619-505fd27cb933 ### ❌ Actual Behavior Editing causes my cursor to move to the end. very bad experience
yindo added the 🐞 bug label 2026-02-21 18:07:24 -05:00
yindo closed this issue 2026-02-21 18:07:24 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Jul 17, 2024):

@qweasdzxcpkh Hello there! I'm a bot that can help you with bug reports, answer your questions, and guide you on becoming a contributor. I'm here to assist you while waiting for a human maintainer.

To resolve the issue in Dify version 0.6.14 where the cursor automatically moves to the end of the text when editing the schema in the tools edit modal, you need to modify the onChange handler of the textarea to preserve the cursor position. Here is the updated code for the textarea component:

<textarea
  value={schema}
  onChange={e => {
    const cursorPosition = e.target.selectionStart;
    setSchema(e.target.value);
    setTimeout(() => {
      e.target.setSelectionRange(cursorPosition, cursorPosition);
    }, 0);
  }}
  className='w-full h-[240px] px-3 py-2 leading-4 text-xs font-normal text-gray-900 bg-gray-100 rounded-lg overflow-y-auto'
  placeholder={t('tools.createTool.schemaPlaceHolder')!}
/>

This change ensures that the cursor position is preserved after the state update. Additionally, you can refer to the GetSchema component in the web/app/components/tools/edit-custom-collection-modal/get-schema.tsx file for more context on how the schema is managed and imported in Dify [1][2].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Jul 17, 2024): <!-- Greeting --> @qweasdzxcpkh Hello there! I'm a bot that can help you with bug reports, answer your questions, and guide you on becoming a contributor. I'm here to assist you while waiting for a human maintainer. <!-- Answer --> To resolve the issue in Dify version 0.6.14 where the cursor automatically moves to the end of the text when editing the schema in the tools edit modal, you need to modify the `onChange` handler of the `textarea` to preserve the cursor position. Here is the updated code for the `textarea` component: ```tsx <textarea value={schema} onChange={e => { const cursorPosition = e.target.selectionStart; setSchema(e.target.value); setTimeout(() => { e.target.setSelectionRange(cursorPosition, cursorPosition); }, 0); }} className='w-full h-[240px] px-3 py-2 leading-4 text-xs font-normal text-gray-900 bg-gray-100 rounded-lg overflow-y-auto' placeholder={t('tools.createTool.schemaPlaceHolder')!} /> ``` This change ensures that the cursor position is preserved after the state update. Additionally, you can refer to the `GetSchema` component in the `web/app/components/tools/edit-custom-collection-modal/get-schema.tsx` file for more context on how the schema is managed and imported in Dify <sup>[[1]](https://github.com/langgenius/dify/blob/main/web/app/components/tools/edit-custom-collection-modal/index.tsx)</sup><sup>[[2]](https://github.com/langgenius/dify/blob/main/web/app/components/tools/edit-custom-collection-modal/get-schema.tsx)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#4652