-
Notifications
You must be signed in to change notification settings - Fork 161
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 #2248 from microsoft/u/juliaroldi/list-delete
Remove whole list when delete
- Loading branch information
Showing
27 changed files
with
1,161 additions
and
25 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
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
2 changes: 1 addition & 1 deletion
2
packages-content-model/roosterjs-content-model-api/lib/modelApi/table/getSelectedCells.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
2 changes: 1 addition & 1 deletion
2
packages-content-model/roosterjs-content-model-api/lib/publicApi/table/setTableCellShade.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
2 changes: 1 addition & 1 deletion
2
...es-content-model/roosterjs-content-model-api/test/modelApi/table/deleteTableColumnTest.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
2 changes: 1 addition & 1 deletion
2
packages-content-model/roosterjs-content-model-api/test/modelApi/table/deleteTableRowTest.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
58 changes: 58 additions & 0 deletions
58
packages-content-model/roosterjs-content-model-core/lib/corePlugin/utils/deleteEmptyList.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,58 @@ | ||
import hasSelectionInBlock from '../../publicApi/selection/hasSelectionInBlock'; | ||
import hasSelectionInBlockGroup from '../../publicApi/selection/hasSelectionInBlockGroup'; | ||
import { getClosestAncestorBlockGroupIndex } from '../../publicApi/model/getClosestAncestorBlockGroupIndex'; | ||
import type { | ||
ContentModelBlock, | ||
DeleteSelectionContext, | ||
DeleteSelectionStep, | ||
} from 'roosterjs-content-model-types'; | ||
|
||
function isEmptyBlock(block: ContentModelBlock | undefined): boolean { | ||
if (block && block.blockType == 'Paragraph') { | ||
return block.segments.every( | ||
segment => segment.segmentType !== 'SelectionMarker' && segment.segmentType == 'Br' | ||
); | ||
} | ||
|
||
if (block && block.blockType == 'BlockGroup') { | ||
return block.blocks.every(isEmptyBlock); | ||
} | ||
|
||
return !!block; | ||
} | ||
|
||
/** | ||
* @internal | ||
* If the first item o the list is selected in a expanded selection, we need to remove the list item levels | ||
* @param context A context object provided by formatContentModel API | ||
*/ | ||
export const deleteEmptyList: DeleteSelectionStep = (context: DeleteSelectionContext) => { | ||
const { insertPoint, deleteResult } = context; | ||
if (deleteResult == 'range' && insertPoint?.path) { | ||
const index = getClosestAncestorBlockGroupIndex( | ||
insertPoint.path, | ||
['ListItem'], | ||
['TableCell'] | ||
); | ||
const item = insertPoint.path[index]; | ||
if (index >= 0 && item && item.blockGroupType == 'ListItem') { | ||
const listItemIndex = insertPoint.path[index + 1].blocks.indexOf(item); | ||
const previousBlock = | ||
listItemIndex > -1 | ||
? insertPoint.path[index + 1].blocks[listItemIndex - 1] | ||
: undefined; | ||
const nextBlock = | ||
listItemIndex > -1 | ||
? insertPoint.path[index + 1].blocks[listItemIndex + 1] | ||
: undefined; | ||
if ( | ||
hasSelectionInBlockGroup(item) && | ||
(!previousBlock || hasSelectionInBlock(previousBlock)) && | ||
nextBlock && | ||
isEmptyBlock(nextBlock) | ||
) { | ||
item.levels = []; | ||
} | ||
} | ||
} | ||
}; |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.