Skip to content

Commit

Permalink
remove getLinkSegment
Browse files Browse the repository at this point in the history
  • Loading branch information
juliaroldi committed Apr 4, 2024
1 parent b1b398e commit c1b2a9d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 220 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { addLink } from 'roosterjs-content-model-dom';
import { getLinkSegment } from './getLinkSegment';
import type { IEditor } from 'roosterjs-content-model-types';
import { formatTextSegmentBeforeSelectionMarker } from '../../pluginUtils/formatTextSegmentBeforeSelectionMarker';
import { matchLink } from 'roosterjs-content-model-api';
import type { IEditor, LinkData } from 'roosterjs-content-model-types';

/**
* @internal
*/
export function createLink(editor: IEditor) {
editor.formatContentModel(model => {
const link = getLinkSegment(model);
if (link && !link.link) {
addLink(link, {
formatTextSegmentBeforeSelectionMarker(editor, (_model, linkSegment, _paragraph) => {
let linkData: LinkData | null = null;
if (!linkSegment.link && (linkData = matchLink(linkSegment.text))) {
addLink(linkSegment, {
format: {
href: link.text,
href: linkData.normalizedUrl,
underline: true,
},
dataset: {},
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { getLinkSegment } from './getLinkSegment';
import { formatTextSegmentBeforeSelectionMarker } from '../../pluginUtils/formatTextSegmentBeforeSelectionMarker';

import type { IEditor } from 'roosterjs-content-model-types';

/**
* @internal
*/
export function unlink(editor: IEditor, rawEvent: KeyboardEvent) {
editor.formatContentModel(model => {
const link = getLinkSegment(model);
if (link?.link) {
link.link = undefined;
formatTextSegmentBeforeSelectionMarker(editor, (_model, linkSegment, _paragraph) => {
if (linkSegment?.link) {
linkSegment.link = undefined;
rawEvent.preventDefault();

return true;
}

return false;
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ describe('createLink', () => {
format: {},
link: {
format: {
href: 'www.bing.com',
href: 'http://www.bing.com',
underline: true,
},
dataset: {},
Expand Down

This file was deleted.

0 comments on commit c1b2a9d

Please sign in to comment.