Skip to content

Commit 5bac841

Browse files
Version bump to 9.19.0 (#2941)
* remove margins on Autoformat plugin * fixes * fix * remove data-istrue * use content change * refactor * Allow skipping marking hasNewContent in `formatContentModel` (#2933) * Fix bridge plugin to be able to handle new event (#2935) * Fix bridge plugin to be able to handle new event * add test * clean LegacySelectionPlugin * Send anchor event in Auto Link (#2934) After a text is automatically transformed into a link by typing and pressing space, send the anchor element when the ContentChanged event is triggered. Also add more unit tests. * Respect font weight in TH element (#2939) * Respect font weight in TH element * add test * improve * fix build * Fix resize table with width (#2940) * Fix resize table with width * fix test * version bump --------- Co-authored-by: Julia Roldi (from Dev Box) <juliaroldi@microsoft.com> Co-authored-by: Julia Roldi <87443959+juliaroldi@users.noreply.github.com>
1 parent e3f54c1 commit 5bac841

File tree

28 files changed

+1874
-162
lines changed

28 files changed

+1874
-162
lines changed

demo/scripts/controlsV2/sidePane/editorOptions/EditorOptionsPlugin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ const initialState: OptionState = {
4747
autoOrdinals: true,
4848
autoMailto: true,
4949
autoTel: true,
50+
removeListMargins: false,
5051
},
5152
markdownOptions: {
5253
bold: true,

demo/scripts/controlsV2/sidePane/editorOptions/ExperimentalFeatures.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ export class ExperimentalFeatures extends React.Component<DefaultFormatProps, {}
1313
<>
1414
{this.renderFeature('PersistCache')}
1515
{this.renderFeature('HandleEnterKey')}
16-
{this.renderFeature('LegacyImageSelection')}
1716
</>
1817
);
1918
}

demo/scripts/controlsV2/sidePane/editorOptions/Plugins.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ export class Plugins extends PluginsBase<keyof BuildInPluginList> {
112112
private autoOrdinals = React.createRef<HTMLInputElement>();
113113
private autoTel = React.createRef<HTMLInputElement>();
114114
private autoMailto = React.createRef<HTMLInputElement>();
115+
private removeListMargins = React.createRef<HTMLInputElement>();
115116
private markdownBold = React.createRef<HTMLInputElement>();
116117
private markdownItalic = React.createRef<HTMLInputElement>();
117118
private markdownStrikethrough = React.createRef<HTMLInputElement>();
@@ -180,6 +181,13 @@ export class Plugins extends PluginsBase<keyof BuildInPluginList> {
180181
this.props.state.autoFormatOptions.autoMailto,
181182
(state, value) => (state.autoFormatOptions.autoMailto = value)
182183
)}
184+
{this.renderCheckBox(
185+
'Remove List Margins',
186+
this.removeListMargins,
187+
this.props.state.autoFormatOptions.removeListMargins,
188+
(state, value) =>
189+
(state.autoFormatOptions.removeListMargins = value)
190+
)}
183191
</>
184192
)}
185193
{this.renderPluginItem(

packages/roosterjs-content-model-core/lib/coreApi/formatContentModel/formatContentModel.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,8 @@ export const formatContentModel: FormatContentModel = (
2525
options,
2626
domToModelOptions
2727
) => {
28-
const {
29-
onNodeCreated,
30-
getChangeData,
31-
rawEvent,
32-
selectionOverride,
33-
scrollCaretIntoView: scroll,
34-
} = options || {};
28+
const { onNodeCreated, rawEvent, selectionOverride, scrollCaretIntoView: scroll } =
29+
options || {};
3530
const model = core.api.createContentModel(core, domToModelOptions, selectionOverride);
3631
const context: FormatContentModelContext = {
3732
newEntities: [],
@@ -47,7 +42,10 @@ export const formatContentModel: FormatContentModel = (
4742

4843
if (changed) {
4944
const isNested = core.undo.isNested;
50-
const shouldAddSnapshot = !skipUndoSnapshot && !isNested;
45+
const shouldAddSnapshot =
46+
(!skipUndoSnapshot || skipUndoSnapshot == 'DoNotSkip') && !isNested;
47+
const shouldMarkNewContent =
48+
(skipUndoSnapshot === true || skipUndoSnapshot == 'MarkNewContent') && !isNested;
5149
let selection: DOMSelection | undefined;
5250

5351
if (shouldAddSnapshot) {
@@ -78,7 +76,7 @@ export const formatContentModel: FormatContentModel = (
7876
contentModel: clearModelCache ? undefined : model,
7977
selection: clearModelCache ? undefined : selection,
8078
source: options?.changeSource || ChangeSource.Format,
81-
data: getChangeData?.(),
79+
data: options?.getChangeData?.(),
8280
formatApiName: options?.apiName,
8381
changedEntities: getChangedEntities(context, rawEvent),
8482
};
@@ -94,7 +92,9 @@ export const formatContentModel: FormatContentModel = (
9492

9593
if (shouldAddSnapshot) {
9694
core.api.addUndoSnapshot(core, false /*canUndoByBackspace*/, entityStates);
97-
} else {
95+
}
96+
97+
if (shouldMarkNewContent) {
9898
core.undo.snapshotsManager.hasNewContent = true;
9999
}
100100
} finally {

packages/roosterjs-content-model-core/lib/corePlugin/selection/SelectionPlugin.ts

Lines changed: 25 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,9 @@ import type {
2121
ParsedTable,
2222
TableSelectionInfo,
2323
TableCellCoordinate,
24-
MouseUpEvent,
2524
} from 'roosterjs-content-model-types';
2625

2726
const MouseLeftButton = 0;
28-
const MouseMiddleButton = 1;
2927
const MouseRightButton = 2;
3028
const Up = 'ArrowUp';
3129
const Down = 'ArrowDown';
@@ -141,7 +139,7 @@ class SelectionPlugin implements PluginWithState<SelectionPluginState> {
141139
break;
142140

143141
case 'mouseUp':
144-
this.onMouseUp(this.editor, event);
142+
this.onMouseUp();
145143
break;
146144

147145
case 'keyDown':
@@ -165,46 +163,30 @@ class SelectionPlugin implements PluginWithState<SelectionPluginState> {
165163
let image: HTMLImageElement | null;
166164

167165
// Image selection
168-
if (editor.isExperimentalFeatureEnabled('LegacyImageSelection')) {
169-
if (
170-
rawEvent.button === MouseRightButton &&
171-
(image =
172-
this.getClickingImage(rawEvent) ??
173-
this.getContainedTargetImage(rawEvent, selection)) &&
174-
image.isContentEditable
175-
) {
176-
this.selectImageWithRange(image, rawEvent);
177-
return;
178-
} else if (selection?.type == 'image' && selection.image !== rawEvent.target) {
179-
this.selectBeforeOrAfterElement(editor, selection.image);
180-
return;
181-
}
182-
} else {
183-
if (
184-
selection?.type == 'image' &&
185-
(rawEvent.button == MouseLeftButton ||
186-
(rawEvent.button == MouseRightButton &&
187-
!this.getClickingImage(rawEvent) &&
188-
!this.getContainedTargetImage(rawEvent, selection)))
189-
) {
190-
this.setDOMSelection(null /*domSelection*/, null /*tableSelection*/);
191-
}
166+
if (
167+
selection?.type == 'image' &&
168+
(rawEvent.button == MouseLeftButton ||
169+
(rawEvent.button == MouseRightButton &&
170+
!this.getClickingImage(rawEvent) &&
171+
!this.getContainedTargetImage(rawEvent, selection)))
172+
) {
173+
this.setDOMSelection(null /*domSelection*/, null /*tableSelection*/);
174+
}
192175

193-
if (
194-
(image =
195-
this.getClickingImage(rawEvent) ??
196-
this.getContainedTargetImage(rawEvent, selection)) &&
197-
image.isContentEditable
198-
) {
199-
this.setDOMSelection(
200-
{
201-
type: 'image',
202-
image: image,
203-
},
204-
null
205-
);
206-
return;
207-
}
176+
if (
177+
(image =
178+
this.getClickingImage(rawEvent) ??
179+
this.getContainedTargetImage(rawEvent, selection)) &&
180+
image.isContentEditable
181+
) {
182+
this.setDOMSelection(
183+
{
184+
type: 'image',
185+
image: image,
186+
},
187+
null
188+
);
189+
return;
208190
}
209191

210192
// Table selection
@@ -245,25 +227,6 @@ class SelectionPlugin implements PluginWithState<SelectionPluginState> {
245227
}
246228
}
247229

248-
private selectImageWithRange(image: HTMLImageElement, event: Event) {
249-
const range = image.ownerDocument.createRange();
250-
range.selectNode(image);
251-
252-
const domSelection = this.editor?.getDOMSelection();
253-
if (domSelection?.type == 'image' && image == domSelection.image) {
254-
event.preventDefault();
255-
} else {
256-
this.setDOMSelection(
257-
{
258-
type: 'range',
259-
isReverted: false,
260-
range,
261-
},
262-
null
263-
);
264-
}
265-
}
266-
267230
private onMouseMove = (event: Event) => {
268231
if (this.editor && this.state.tableSelection) {
269232
const hasTableSelection = !!this.state.tableSelection.lastCo;
@@ -324,21 +287,7 @@ class SelectionPlugin implements PluginWithState<SelectionPluginState> {
324287
}
325288
};
326289

327-
private onMouseUp(editor: IEditor, event: MouseUpEvent) {
328-
let image: HTMLImageElement | null;
329-
330-
if (
331-
editor.isExperimentalFeatureEnabled('LegacyImageSelection') &&
332-
(image = this.getClickingImage(event.rawEvent)) &&
333-
image.isContentEditable &&
334-
event.rawEvent.button != MouseMiddleButton &&
335-
(event.rawEvent.button ==
336-
MouseRightButton /* it's not possible to drag using right click */ ||
337-
event.isClicking)
338-
) {
339-
this.selectImageWithRange(image, event.rawEvent);
340-
}
341-
290+
private onMouseUp() {
342291
this.detachMouseEvent();
343292
}
344293

0 commit comments

Comments
 (0)