Skip to content

Commit 30f2504

Browse files
authored
fix(rich-text-editor): DP-179947 use URL as display text when inserting link without text (#1202)
1 parent 9971fc0 commit 30f2504

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

packages/dialtone-vue/components/rich_text_editor/rich_text_editor.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,6 +1633,26 @@ describe('DtRichTextEditor tests', () => {
16331633
});
16341634
});
16351635

1636+
describe('setLink method', () => {
1637+
const linkOptions = { class: 'd-link' };
1638+
const supportedProtocols = [/^https?:\/\//, /^ftp?:\/\//, /mailto:/];
1639+
const defaultPrefix = 'https://';
1640+
1641+
beforeEach(async () => {
1642+
await wrapper.setProps({ link: true, outputFormat: 'html' });
1643+
wrapper.vm.editor.commands.focus();
1644+
});
1645+
1646+
it.each([
1647+
['https://example.com', 'Example', 'Example'],
1648+
['https://example.com', '', 'https://example.com'],
1649+
])('should render link correctly (url=%s, displayText=%s)', async (url, displayText, expectedSubstring) => {
1650+
wrapper.vm.setLink(url, displayText, linkOptions, supportedProtocols, defaultPrefix);
1651+
await wrapper.vm.$nextTick();
1652+
expect(wrapper.vm.getOutput()).toContain(expectedSubstring);
1653+
});
1654+
});
1655+
16361656
describe('Link keyboard shortcut functionality', () => {
16371657
describe('When Mod+K is pressed and link is enabled', () => {
16381658
it('should emit edit-link event', async () => {

packages/dialtone-vue/components/rich_text_editor/rich_text_editor.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -974,12 +974,13 @@ export default {
974974
.run();
975975
976976
const selection = this.editor?.view?.state?.selection;
977+
const displayText = linkText || linkInput;
977978
978979
this.editor
979980
.chain()
980981
.focus()
981-
.insertContent(linkText)
982-
.setTextSelection({ from: selection.from, to: selection.from + linkText.length })
982+
.insertContent(displayText)
983+
.setTextSelection({ from: selection.from, to: selection.from + displayText.length })
983984
.setLink({ href: linkInput, class: linkOptions.class })
984985
.run();
985986
},

0 commit comments

Comments
 (0)