BoldDesk®Customer service software with ticketing, live chat & omnichannel support, starting at $99/mo for unlimited agents. Try for free!
Hello, could you help me? I need to detect if a "Section Break" is present in the selection. How can I do that?
I already tried using selection.text
, but it detects it as \r
, the same as when I press Enter in the document.
Hi Oleksandr,
The start and end offsets of a selection can be obtained using the selection module. The initial index in the offset corresponds to the section index.
Element | Hierarchical Format | Explanation |
---|---|---|
Move selection to Paragraph | sectionIndex;blockIndex;offset Ex: 0;0;0 | It moves the cursor to the start of paragraph. |
On the selection change event, retrieve the start and end offsets and compare their section indices. A section break exists if the section indices differ; if they are the same, no section break is present within the selection.
Move selection to position in React Document editor | Syncfusion
Please let us know whether this solution meets your requirements
Regards,
Dhanush S
Thank you, Dhanush.
I have another question: what should I do if I select only the Section Break?
As you can see in the screenshot, the startOffset
is 2;31;0
and the endOffset
is 2;32;1
Screenshort:
Hi Olaksandr,
The provided screenshot has been reviewed, and it has been confirmed that the selection does not span across the section break. The selected paragraph is located within the same section, which means the section index remains unchanged. This is the expected behavior.
Regards,
Dhanush S
I understand it, do you have any solutions on how I can catch this?
Hi Olaksandr,
It's not possible to achieve your requirement.
Could you please share more details about your use case? So, we can check the alternative solution from our end.
Regards,
Dhanush S
Sure, I want to prevent remove "Section Break".
Example of my code to detect if user selects text in two sections. Thanks for helping with this.
if (code === 'Backspace' || code === 'Delete') { const docEditor = args.source; const { selection } = docEditor; const { startOffset, endOffset } = selection; const startSectionIndex = startOffset.split(';')[0]; const endSectionIndex = endOffset.split(';')[0]; if (startSectionIndex !== endSectionIndex) { wordRootStore.modals.openModal('DeleteSectionBreak'); eventPreventDefault(args); } }
But I also need to prevent deletion if the user selects only a section break.
Hi Olaksandr,
We apologize for the delay.
We have validated your query, and it's impossible to achieve your requirement using Document editor
Regards,
Dhanush S
Hi Olaksandr,
We apologize for the delay.
We have validated your query, and it's impossible to achieve your requirement using Document editor
Regards,
Dhanush S