-
Notifications
You must be signed in to change notification settings - Fork 158
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
[Part 1] Port Auto Link #2479
Merged
Merged
[Part 1] Port Auto Link #2479
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
7cbe150
add link features
juliaroldi 7468d05
conflicts
juliaroldi 4ae705a
fix build
juliaroldi 7966758
conflicts
juliaroldi d7b4c7c
fixes
juliaroldi d2a02ab
fix comment
juliaroldi cbe3ff9
remove unnecessary code
juliaroldi 4aa88fd
remove unnecessary code
juliaroldi 542e0f1
fixes
juliaroldi 560035b
Merge branch 'master' into u/juliaroldi/auto-link
juliaroldi 53aad43
Merge branch 'master' into u/juliaroldi/auto-link
juliaroldi 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
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
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
3 changes: 2 additions & 1 deletion
3
packages/roosterjs-content-model-api/test/modelApi/link/matchLinkTest.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
25 changes: 25 additions & 0 deletions
25
packages/roosterjs-content-model-plugins/lib/autoFormat/link/createLink.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,25 @@ | ||
import { addLink } from 'roosterjs-content-model-dom'; | ||
import { getLinkSegment } from './getLinkSegment'; | ||
import type { IEditor } from 'roosterjs-content-model-types'; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export function createLink(editor: IEditor) { | ||
editor.formatContentModel(model => { | ||
const link = getLinkSegment(model); | ||
if (link && !link.link) { | ||
addLink(link, { | ||
format: { | ||
href: link.text, | ||
underline: true, | ||
}, | ||
dataset: {}, | ||
}); | ||
|
||
return true; | ||
} | ||
|
||
return false; | ||
}); | ||
} |
29 changes: 29 additions & 0 deletions
29
packages/roosterjs-content-model-plugins/lib/autoFormat/link/getLinkSegment.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,29 @@ | ||
import { getSelectedSegmentsAndParagraphs } from 'roosterjs-content-model-core'; | ||
import { matchLink } from 'roosterjs-content-model-api'; | ||
import type { ContentModelDocument } from 'roosterjs-content-model-types'; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export function getLinkSegment(model: ContentModelDocument) { | ||
const selectedSegmentsAndParagraphs = getSelectedSegmentsAndParagraphs( | ||
model, | ||
false /* includingFormatHolder */ | ||
); | ||
if (selectedSegmentsAndParagraphs.length == 1 && selectedSegmentsAndParagraphs[0][1]) { | ||
const selectedParagraph = selectedSegmentsAndParagraphs[0][1]; | ||
const marker = selectedParagraph.segments[selectedParagraph.segments.length - 1]; | ||
const link = selectedParagraph.segments[selectedParagraph.segments.length - 2]; | ||
if ( | ||
marker && | ||
link && | ||
marker.segmentType === 'SelectionMarker' && | ||
marker.isSelected && | ||
link.segmentType === 'Text' && | ||
(matchLink(link.text) || link.link) | ||
) { | ||
return link; | ||
} | ||
} | ||
return undefined; | ||
} |
18 changes: 18 additions & 0 deletions
18
packages/roosterjs-content-model-plugins/lib/autoFormat/link/unlink.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,18 @@ | ||
import { getLinkSegment } from './getLinkSegment'; | ||
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; | ||
rawEvent.preventDefault(); | ||
return true; | ||
} | ||
|
||
return false; | ||
}); | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...ins/lib/autoFormat/keyboardListTrigger.ts → ...ib/autoFormat/list/keyboardListTrigger.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
Oops, something went wrong.
Oops, something went wrong.
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.
The original auto link feature also work when press SPACE or ENTER
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.
I see you put it in part 2. that is ok.