-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2847 from microsoft/u/nguyenvi/versionbump
Version bump to main 9.12.0 and legacyAdapter 8.62.2
- Loading branch information
Showing
31 changed files
with
3,313 additions
and
381 deletions.
There are no files selected for viewing
This file contains 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 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
48 changes: 48 additions & 0 deletions
48
packages/roosterjs-content-model-api/lib/modelApi/link/promoteLink.ts
This file contains 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,48 @@ | ||
import { getLinkUrl } from './getLinkUrl'; | ||
import { splitTextSegment } from '../../publicApi/segment/splitTextSegment'; | ||
import type { | ||
AutoLinkOptions, | ||
ContentModelText, | ||
ShallowMutableContentModelParagraph, | ||
} from 'roosterjs-content-model-types'; | ||
|
||
/** | ||
* Promote the given text segment to a hyper link when the segment text is ending with a valid link format. | ||
* When the whole text segment if of a link, promote the whole segment. | ||
* When the text segment ends with a link format, split the segment and promote the second part | ||
* When link is in middle of the text segment, no action. | ||
* This is mainly used for doing auto link when there is a link before cursor | ||
* @param segment The text segment to search link text from | ||
* @param paragraph Parent paragraph of the segment | ||
* @param options Options of auto link | ||
* @returns If a link is promoted, return this segment. Otherwise return null | ||
*/ | ||
export function promoteLink( | ||
segment: ContentModelText, | ||
paragraph: ShallowMutableContentModelParagraph, | ||
autoLinkOptions: AutoLinkOptions | ||
): ContentModelText | null { | ||
const link = segment.text.split(' ').pop(); | ||
const url = link?.trim(); | ||
let linkUrl: string | undefined = undefined; | ||
|
||
if (url && link && (linkUrl = getLinkUrl(url, autoLinkOptions))) { | ||
const linkSegment = splitTextSegment( | ||
segment, | ||
paragraph, | ||
segment.text.length - link.trimLeft().length, | ||
segment.text.trimRight().length | ||
); | ||
linkSegment.link = { | ||
format: { | ||
href: linkUrl, | ||
underline: true, | ||
}, | ||
dataset: {}, | ||
}; | ||
|
||
return linkSegment; | ||
} | ||
|
||
return null; | ||
} |
4 changes: 2 additions & 2 deletions
4
...ns/test/autoFormat/link/getLinkUrlTest.ts → ...-api/test/modelApi/link/getLinkUrlTest.ts
This file contains 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 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 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 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 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 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 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 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
Oops, something went wrong.