-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into u/jisong/2202_2
- Loading branch information
Showing
11 changed files
with
2,067 additions
and
34 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
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
41 changes: 41 additions & 0 deletions
41
packages-content-model/roosterjs-content-model-plugins/lib/edit/tabUtils/handleTabOnList.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,41 @@ | ||
import { handleTabOnParagraph } from './handleTabOnParagraph'; | ||
import { setModelIndentation } from 'roosterjs-content-model-api'; | ||
import type { ContentModelDocument, ContentModelListItem } from 'roosterjs-content-model-types'; | ||
|
||
/** | ||
* 1. When the selection is collapsed and the cursor is at start of a list item, call setModelIndentation. | ||
* 2. Otherwise call handleTabOnParagraph. | ||
* @internal | ||
*/ | ||
export function handleTabOnList( | ||
model: ContentModelDocument, | ||
listItem: ContentModelListItem, | ||
rawEvent: KeyboardEvent | ||
) { | ||
const selectedParagraph = findSelectedParagraph(listItem); | ||
if ( | ||
!isMarkerAtStartOfBlock(listItem) && | ||
selectedParagraph.length == 1 && | ||
selectedParagraph[0].blockType === 'Paragraph' | ||
) { | ||
return handleTabOnParagraph(model, selectedParagraph[0], rawEvent); | ||
} else { | ||
setModelIndentation(model, rawEvent.shiftKey ? 'outdent' : 'indent'); | ||
rawEvent.preventDefault(); | ||
return true; | ||
} | ||
} | ||
|
||
function isMarkerAtStartOfBlock(listItem: ContentModelListItem) { | ||
return ( | ||
listItem.blocks[0].blockType == 'Paragraph' && | ||
listItem.blocks[0].segments[0].segmentType == 'SelectionMarker' | ||
); | ||
} | ||
|
||
function findSelectedParagraph(listItem: ContentModelListItem) { | ||
return listItem.blocks.filter( | ||
block => | ||
block.blockType == 'Paragraph' && block.segments.some(segment => segment.isSelected) | ||
); | ||
} |
Oops, something went wrong.