-
Notifications
You must be signed in to change notification settings - Fork 165
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/juliaroldi/auto-format-demo-site
- Loading branch information
Showing
8 changed files
with
1,808 additions
and
13 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
24 changes: 24 additions & 0 deletions
24
packages/roosterjs-content-model-plugins/lib/edit/tabUtils/handleTabOnTable.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,24 @@ | ||
import { getFirstSelectedTable } from 'roosterjs-content-model-dom'; | ||
import { setModelIndentation } from 'roosterjs-content-model-api'; | ||
import type { ContentModelDocument, ContentModelTable } from 'roosterjs-content-model-types'; | ||
|
||
/** | ||
* When the whole table is selected, indent or outdent the whole table with setModelIndentation. | ||
* @internal | ||
*/ | ||
export function handleTabOnTable(model: ContentModelDocument, rawEvent: KeyboardEvent) { | ||
const tableModel = getFirstSelectedTable(model)[0]; | ||
if (tableModel && isWholeTableSelected(tableModel)) { | ||
setModelIndentation(model, rawEvent.shiftKey ? 'outdent' : 'indent'); | ||
rawEvent.preventDefault(); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
function isWholeTableSelected(tableModel: ContentModelTable) { | ||
return ( | ||
tableModel.rows[0]?.cells[0]?.isSelected && | ||
tableModel.rows[tableModel.rows.length - 1]?.cells[tableModel.widths.length - 1]?.isSelected | ||
); | ||
} |
53 changes: 53 additions & 0 deletions
53
packages/roosterjs-content-model-plugins/lib/edit/tabUtils/handleTabOnTableCell.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,53 @@ | ||
import { clearSelectedCells, insertTableRow } from 'roosterjs-content-model-api'; | ||
import { | ||
createSelectionMarker, | ||
getFirstSelectedTable, | ||
normalizeTable, | ||
setParagraphNotImplicit, | ||
setSelection, | ||
} from 'roosterjs-content-model-dom'; | ||
import type { ContentModelDocument, ContentModelTableCell } from 'roosterjs-content-model-types'; | ||
|
||
/** | ||
* When the cursor is on the last cell of a table, add new row and focus first new cell. | ||
* @internal | ||
*/ | ||
export function handleTabOnTableCell( | ||
model: ContentModelDocument, | ||
cell: ContentModelTableCell, | ||
rawEvent: KeyboardEvent | ||
) { | ||
const tableModel = getFirstSelectedTable(model)[0]; | ||
// Check if cursor is on last cell of the table | ||
if ( | ||
!rawEvent.shiftKey && | ||
tableModel && | ||
tableModel.rows[tableModel.rows.length - 1]?.cells[tableModel.widths.length - 1] === cell | ||
) { | ||
insertTableRow(tableModel, 'insertBelow'); | ||
|
||
// Clear Table selection | ||
clearSelectedCells(tableModel, { | ||
firstRow: tableModel.rows.length - 1, | ||
firstColumn: 0, | ||
lastRow: tableModel.rows.length - 1, | ||
lastColumn: tableModel.widths.length - 1, | ||
}); | ||
normalizeTable(tableModel, model.format); | ||
|
||
// Add selection marker to the first cell of the new row | ||
const markerParagraph = tableModel.rows[tableModel.rows.length - 1]?.cells[0]?.blocks[0]; | ||
if (markerParagraph.blockType == 'Paragraph') { | ||
const marker = createSelectionMarker(model.format); | ||
|
||
markerParagraph.segments.unshift(marker); | ||
setParagraphNotImplicit(markerParagraph); | ||
setSelection(tableModel.rows[tableModel.rows.length - 1].cells[0], marker); | ||
} | ||
|
||
rawEvent.preventDefault(); | ||
return true; | ||
} | ||
|
||
return false; | ||
} |
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.