-
Notifications
You must be signed in to change notification settings - Fork 111
remove old link when editing #5690
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
grnd-alt
merged 9 commits into
main
from
fix/5516-updating-the-url-of-a-link-via-toolbar-menu-splits-the-link
Mar 20, 2025
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9fbd73b
remove old link when editing
grnd-alt 2b1ce9a
refactor(links): add insertOrSetLink command
max-nextcloud ed3a6d8
refactor(cy): move Links.spec.js into e2e folder
max-nextcloud 3c7aee6
test(cy): initial test for the link mark
max-nextcloud 6539ff7
test(cy): adjust import path in moved Links.spec.js
max-nextcloud c1ef403
refactor(link): use isMarkActive in insertOrSetLink
max-nextcloud 819ea95
fix: replace link correctly
grnd-alt 0c3bcad
fix: dont overwrite other link commands
grnd-alt 08a528b
use snapshots for long test results
grnd-alt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: replace link correctly
Signed-off-by: grnd-alt <[email protected]>
- Loading branch information
commit 819ea959c1c4ab8a6dac2a9e7fe1e6f8191b3dd3
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,24 +1,6 @@ | ||
| /* eslint-disable no-unused-expressions */ | ||
| /** | ||
| * @copyright Copyright (c) 2024 Max <[email protected]> | ||
| * | ||
| * @author Max <[email protected]> | ||
| * | ||
| * @license AGPL-3.0-or-later | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as | ||
| * published by the Free Software Foundation, either version 3 of the | ||
| * License, or (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| * | ||
| * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| import Markdown from './../../../src/extensions/Markdown.js' | ||
|
|
@@ -27,68 +9,37 @@ import { createCustomEditor } from './../../support/components.js' | |
| import { loadMarkdown, expectMarkdown } from '../nodes/helpers.js' | ||
|
|
||
| describe('Link marks', { retries: 0 }, () => { | ||
|
|
||
| const editor = createCustomEditor({ | ||
| content: '', | ||
| extensions: [ | ||
| Markdown, | ||
| Link, | ||
| Italic, | ||
| ], | ||
| extensions: [Markdown, Link, Italic], | ||
| }) | ||
|
|
||
| describe('insertOrSetLink command', { retries: 0 }, () => { | ||
|
|
||
| it('is available in commands', () => { | ||
| expect(editor.commands).to.have.property('insertOrSetLink') | ||
| }) | ||
|
|
||
| it('can run on normal paragraph', () => { | ||
| prepareEditor('hello\n', 3) | ||
| expect(editor.can().insertOrSetLink()).to.be.ok | ||
| expect(editor.can().insertOrSetLink()).toBe(true) | ||
| }) | ||
|
|
||
| it('will insert a link in a normal paragraph', () => { | ||
| prepareEditor('hello\n', 3) | ||
| editor.commands.insertOrSetLink('https://nextcloud.com', { href: 'https://nextcloud.com' }) | ||
| editor.commands.insertOrSetLink('https://nextcloud.com', { | ||
| href: 'https://nextcloud.com', | ||
| }) | ||
| expectMarkdown(editor, 'he\n\n<https://nextcloud.com>\n\nllo') | ||
| }) | ||
|
|
||
| }) | ||
|
|
||
| /** | ||
| * Expect a link in the editor. | ||
| */ | ||
| function expectLink() { | ||
| expect(getParentNode().type.name).to.equal('paragraph') | ||
| expect(getParentNode().attrs.href).to.equal('https://nextcloud.com') | ||
| expect(getMark().attrs.href).to.equal('https://nextcloud.com') | ||
| } | ||
|
|
||
| /** | ||
| * | ||
| */ | ||
| function getParentNode() { | ||
| const { state: { selection } } = editor | ||
| return selection.$head.parent | ||
| } | ||
|
|
||
| /** | ||
| * | ||
| */ | ||
| function getMark() { | ||
| const { state: { selection } } = editor | ||
| console.info(selection.$head) | ||
| return selection.$head.nodeAfter.marks[0] | ||
| } | ||
|
|
||
| /** | ||
| * | ||
| * @param input | ||
| * @param {*} input markdown content | ||
| * @param {*} position cursor pos | ||
| */ | ||
| function prepareEditor(input, position = 1) { | ||
| loadMarkdown(editor, input) | ||
| editor.commands.setTextSelection( position ) | ||
| editor.commands.setTextSelection(position) | ||
| } | ||
|
|
||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| /** | ||
| * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
| import Link from './../../marks/Link.js' | ||
| import Underline from '../../marks/Underline.js' | ||
| import createCustomEditor from '../testHelpers/createCustomEditor.ts' | ||
|
|
||
| describe('Link extension integrated in the editor', () => { | ||
| it('should have link available in commands', () => { | ||
| const editor = createCustomEditor('<p><a href="nextcloud.com">Test</a> HELLO WORLD</p>', [Link]) | ||
| expect(editor.commands).toHaveProperty('insertOrSetLink') | ||
| }) | ||
|
|
||
| it('should update link if anchor has mark', () => { | ||
| const editor = createCustomEditor( | ||
| '<p><a href="nextcloud.com">Te<u>s</u>t</a> HELLO WORLD</p>', | ||
| [Link, Underline], | ||
| ) | ||
| editor.commands.setTextSelection(3) | ||
| editor.commands.insertOrSetLink('updated.de', { href: 'updated.de' }) | ||
| expect(editor.getJSON()).toEqual({ | ||
| content: [ | ||
| { | ||
| content: [ | ||
| { | ||
| marks: [ | ||
| { attrs: { href: 'updated.de', title: null }, type: 'link' }, | ||
| ], | ||
| text: 'updated.de', | ||
| type: 'text', | ||
| }, | ||
| { text: ' HELLO WORLD', type: 'text' }, | ||
| ], | ||
| type: 'paragraph', | ||
| }, | ||
| ], | ||
| type: 'doc', | ||
| }) | ||
| }) | ||
|
|
||
| it('Should only update link the anchor is on', () => { | ||
| const editor = createCustomEditor( | ||
| '<p><a href="nextcloud.com">Test</a><a href="not-nextcloud.com">second link</a></p>', | ||
| [Link], | ||
| ) | ||
| editor.commands.setTextSelection(3) | ||
| editor.commands.insertOrSetLink('updated.de', { href: 'updated.de' }) | ||
| expect(editor.getJSON()).toEqual({ | ||
| content: [ | ||
| { | ||
| content: [ | ||
| { | ||
| marks: [ | ||
| { attrs: { href: 'updated.de', title: null }, type: 'link' }, | ||
| ], | ||
| text: 'updated.de', | ||
| type: 'text', | ||
| }, | ||
| { | ||
| marks: [ | ||
| { | ||
| attrs: { | ||
| href: 'not-nextcloud.com', | ||
| title: null, | ||
| }, | ||
| type: 'link', | ||
| }, | ||
| ], | ||
| text: 'second link', | ||
| type: 'text', | ||
| }, | ||
| ], | ||
| type: 'paragraph', | ||
| }, | ||
| ], | ||
| type: 'doc', | ||
| }) | ||
| }) | ||
|
|
||
| it('should insert new link if none at anchor', () => { | ||
| const editor = createCustomEditor( | ||
| '<p><a href="nextcloud.com">Test</a> HELLO WORLD</p>', | ||
| [Link], | ||
| ) | ||
| editor.commands.setTextSelection(10) | ||
| expect(editor.getJSON()).toEqual({ | ||
| content: [ | ||
| { | ||
| content: [ | ||
| { | ||
| marks: [ | ||
| { attrs: { href: 'nextcloud.com', title: null }, type: 'link' }, | ||
| ], | ||
| text: 'Test', | ||
| type: 'text', | ||
| }, | ||
| { text: ' HELLO WORLD', type: 'text' }, | ||
| ], | ||
| type: 'paragraph', | ||
| }, | ||
| ], | ||
| type: 'doc', | ||
| }) | ||
| }) | ||
| }) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test seems incomplete. It does not change anything but just asserts the initial state.