Skip to content
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

Bump Core, Plugins and Dom packages to 9.11.2 #2826

Merged
merged 24 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
73809cb
Add a ID to the TempDiv, to be able to identify on blur was caused fo…
BryanValverdeU Sep 30, 2024
1fa9459
delete image range
juliaroldi Sep 30, 2024
4c69cb9
remove selection
juliaroldi Sep 30, 2024
78e94ee
fix build
juliaroldi Sep 30, 2024
764748b
WIP
juliaroldi Oct 1, 2024
46e343f
clean info when delete image
juliaroldi Oct 1, 2024
eb4127c
Merge pull request #2817 from microsoft/u/juliaroldi/fix-cursor
juliaroldi Oct 1, 2024
78ba62f
WIP
juliaroldi Oct 1, 2024
d9c9b03
WIP
juliaroldi Oct 1, 2024
c338ce1
Merge branch 'master' of https://github.com/microsoft/roosterjs into …
juliaroldi Oct 1, 2024
9db6c8d
add unit tests
juliaroldi Oct 4, 2024
c2dc635
nit
juliaroldi Oct 4, 2024
2d90d5c
Remove style "white-space" from empty paragraph (#2820)
JiuqingSong Oct 5, 2024
3415d5a
Fix #2804 (#2821)
JiuqingSong Oct 5, 2024
ab3ccc8
Merge branch 'master' into u/juliaroldi/remove-selection
juliaroldi Oct 7, 2024
c0b5f41
Merge pull request #2818 from microsoft/u/juliaroldi/remove-selection
juliaroldi Oct 7, 2024
e9ec464
touch images
juliaroldi Oct 8, 2024
10ee478
Do not treat image without src as empty image (#2823)
JiuqingSong Oct 8, 2024
7143071
Merge branch 'master' of https://github.com/microsoft/roosterjs into …
BryanValverdeU Oct 11, 2024
7e88e11
update versions.json
BryanValverdeU Oct 11, 2024
39cfe66
Merge branch 'master' into u/juliaroldi/image-touch
juliaroldi Oct 11, 2024
84bad41
Merge pull request #2822 from microsoft/u/juliaroldi/image-touch
juliaroldi Oct 11, 2024
f8c7e19
Merge branch 'master' of https://github.com/microsoft/roosterjs into …
juliaroldi Oct 11, 2024
be29ad2
update versions
BryanValverdeU Oct 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {
EmptySegmentFormat,
addCode,
addLink,
createParagraph,
createSelectionMarker,
createText,
Expand Down Expand Up @@ -448,6 +450,16 @@ export class DomIndexerImpl implements DomIndexer {
const marker = createSelectionMarker(first.format);
newSegments.push(marker);

if (startOffset < (textNode.nodeValue ?? '').length) {
if (first.link) {
addLink(marker, first.link);
}

if (first.code) {
addCode(marker, first.code);
}
}

selectable = marker;
endOffset = startOffset;
} else if (endOffset > startOffset) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import {
CacheSelection,
ContentModelDocument,
ContentModelLink,
ContentModelSegment,
DOMSelection,
} from 'roosterjs-content-model-types';
Expand Down Expand Up @@ -934,6 +935,63 @@ describe('domIndexerImpl.reconcileSelection', () => {
],
});
});

it('Existing text has link', () => {
const node = document.createTextNode('test') as any;
const newRangeEx: DOMSelection = {
type: 'range',
range: createRange(node, 2),
isReverted: false,
};
const link: ContentModelLink = {
dataset: {},
format: {
href: 'test',
},
};
const paragraph = createParagraph();
const segment = createText('', {}, link);

paragraph.segments.push(segment);
domIndexerImpl.onSegment(node, paragraph, [segment]);

const result = domIndexerImpl.reconcileSelection(model, newRangeEx);

const segment1: ContentModelSegment = {
segmentType: 'Text',
text: 'te',
format: {},
link,
};
const segment2: ContentModelSegment = {
segmentType: 'Text',
text: 'st',
format: {},
link,
};

expect(result).toBeTrue();
expect(node.__roosterjsContentModel).toEqual({
paragraph,
segments: [segment1, segment2],
});
expect(paragraph).toEqual({
blockType: 'Paragraph',
format: {},
segments: [
segment1,
{
segmentType: 'SelectionMarker',
format: {},
isSelected: true,
link,
},
segment2,
],
});
expect(setSelectionSpy).not.toHaveBeenCalled();
expect(model.hasRevertedRangeSelection).toBeFalsy();
});
});

describe('domIndexerImpl.reconcileChildList', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export function normalizeParagraph(paragraph: ReadonlyContentModelParagraph) {
mutateBlock(paragraph).segments.pop();
}
}

normalizeParagraphStyle(paragraph);
}

if (!isWhiteSpacePreserved(paragraph.format.whiteSpace)) {
Expand All @@ -51,6 +53,18 @@ export function normalizeParagraph(paragraph: ReadonlyContentModelParagraph) {
moveUpSegmentFormat(paragraph);
}

function normalizeParagraphStyle(paragraph: ReadonlyContentModelParagraph) {
// New paragraph should not have white-space style
if (
paragraph.format.whiteSpace &&
paragraph.segments.every(
seg => seg.segmentType == 'Br' || seg.segmentType == 'SelectionMarker'
)
) {
delete mutateBlock(paragraph).format.whiteSpace;
}
}

function removeEmptySegments(block: ReadonlyContentModelParagraph) {
for (let j = block.segments.length - 1; j >= 0; j--) {
if (isSegmentEmpty(block.segments[j])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -809,4 +809,34 @@ describe('Move up format', () => {
cachedElement: mockedCache,
});
});

it('Empty paragraph has white-space style', () => {
const para = createParagraph(false, { whiteSpace: 'pre-wrap' });
const br = createBr();

para.segments.push(br);

normalizeParagraph(para);

expect(para).toEqual({
blockType: 'Paragraph',
segments: [br],
format: {},
});
});

it('Paragraph has content and white-space style', () => {
const para = createParagraph(false, { whiteSpace: 'pre-wrap' });
const text = createText('test');

para.segments.push(text);

normalizeParagraph(para);

expect(para).toEqual({
blockType: 'Paragraph',
segments: [text],
format: { whiteSpace: 'pre-wrap' },
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import { Resizer } from './Resizer/resizerContext';
import { Rotator } from './Rotator/rotatorContext';
import { updateRotateHandle } from './Rotator/updateRotateHandle';
import { updateWrapper } from './utils/updateWrapper';

import {
ChangeSource,
getSafeIdSelector,
getSelectedParagraphs,
isElementOfType,
isNodeOfType,
mutateBlock,
Expand Down Expand Up @@ -254,21 +254,26 @@ export class ImageEditPlugin implements ImageEditor, EditorPlugin {
}
}

private applyFormatWithContentModel(
/**
* EXPOSED FOR TESTING PURPOSE ONLY
*/
protected applyFormatWithContentModel(
editor: IEditor,
isCropMode: boolean,
shouldSelectImage: boolean,
isApiOperation?: boolean
) {
let editingImageModel: ContentModelImage | undefined;
const selection = editor.getDOMSelection();

editor.formatContentModel(
model => {
const editingImage = getSelectedImage(model);
const previousSelectedImage = isApiOperation
? editingImage
: findEditingImage(model);
let result = false;

if (
shouldSelectImage ||
previousSelectedImage?.image != editingImage?.image ||
Expand Down Expand Up @@ -301,6 +306,16 @@ export class ImageEditPlugin implements ImageEditor, EditorPlugin {
image.isSelected = shouldSelectImage;
image.isSelectedAsImageSelection = shouldSelectImage;
delete image.dataset.isEditing;

if (selection?.type == 'range' && !selection.range.collapsed) {
const selectedParagraphs = getSelectedParagraphs(model, true);
const isImageInRange = selectedParagraphs.some(paragraph =>
paragraph.segments.includes(image)
);
if (isImageInRange) {
image.isSelected = true;
}
}
}
);

Expand All @@ -314,6 +329,7 @@ export class ImageEditPlugin implements ImageEditor, EditorPlugin {

this.isEditing = false;
this.isCropMode = false;

if (
editingImage &&
selection?.type == 'image' &&
Expand Down Expand Up @@ -404,6 +420,7 @@ export class ImageEditPlugin implements ImageEditor, EditorPlugin {
if (this.imageEditInfo) {
this.startEditing(editor, image, ['resize', 'rotate']);
if (this.selectedImage && this.imageEditInfo && this.wrapper && this.clonedImage) {
const isMobileOrTable = !!editor.getEnvironment().isMobileOrTablet;
this.dndHelpers = [
...getDropAndDragHelpers(
this.wrapper,
Expand All @@ -429,7 +446,8 @@ export class ImageEditPlugin implements ImageEditor, EditorPlugin {
this.wasImageResized = true;
}
},
this.zoomScale
this.zoomScale,
isMobileOrTable
),
...getDropAndDragHelpers(
this.wrapper,
Expand Down Expand Up @@ -460,7 +478,8 @@ export class ImageEditPlugin implements ImageEditor, EditorPlugin {
);
}
},
this.zoomScale
this.zoomScale,
isMobileOrTable
),
];

Expand Down Expand Up @@ -555,7 +574,8 @@ export class ImageEditPlugin implements ImageEditor, EditorPlugin {
this.isCropMode = true;
}
},
this.zoomScale
this.zoomScale,
!!editor.getEnvironment().isMobileOrTablet
),
];
updateWrapper(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export function getDropAndDragHelpers(
elementClass: ImageEditElementClass,
helper: DragAndDropHandler<DragAndDropContext, any>,
updateWrapper: (context: DragAndDropContext, _handle: HTMLElement) => void,
zoomScale: number
zoomScale: number,
useTouch: boolean
): DragAndDropHelper<DragAndDropContext, any>[] {
return getEditElements(wrapper, elementClass).map(
element =>
Expand All @@ -31,7 +32,8 @@ export function getDropAndDragHelpers(
},
updateWrapper,
helper,
zoomScale
zoomScale,
useTouch
)
);
}
Expand Down
Loading
Loading