From 993475a0ea6685106003fcb4de85afa70653d87a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=86=8A=E6=99=AF=E4=BC=9F?= <1054417359@qq.com> Date: Tue, 9 Aug 2022 14:55:08 +0800 Subject: [PATCH 1/3] fix:ImageEdit Plugin minWidth or minHeight work failed --- .../plugins/ImageEdit/imageEditors/Resizer.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/roosterjs-editor-plugins/lib/plugins/ImageEdit/imageEditors/Resizer.ts b/packages/roosterjs-editor-plugins/lib/plugins/ImageEdit/imageEditors/Resizer.ts index bcf4dbdd661..92655e3febd 100644 --- a/packages/roosterjs-editor-plugins/lib/plugins/ImageEdit/imageEditors/Resizer.ts +++ b/packages/roosterjs-editor-plugins/lib/plugins/ImageEdit/imageEditors/Resizer.ts @@ -51,14 +51,21 @@ export const Resizer: DragAndDropHandler = { : Math.max(base.heightPx + deltaY * (y == 'n' ? -1 : 1), options.minHeight); if (shouldPreserveRatio && ratio > 0) { - newHeight = Math.min(newHeight, newWidth / ratio); - newWidth = Math.min(newWidth, newHeight * ratio); - - if (newWidth < newHeight * ratio) { + if (ratio > 1) { + // first sure newHeight is right,calculate newWidth newWidth = newHeight * ratio; - } else { + if (newWidth < options.minWidth) { + newWidth = options.minWidth; + newHeight = newWidth / ratio; + } + } else { + // first sure newWidth is right,calculate newHeight newHeight = newWidth / ratio; - } + if (newHeight < options.minHeight) { + newHeight = options.minHeight; + newWidth = newHeight * ratio; + } + } } editInfo.widthPx = newWidth; From b50dbc984fdbb9db93b5743d7ba4269c7fbd1ebd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=86=8A=E6=99=AF=E4=BC=9F?= <1054417359@qq.com> Date: Fri, 12 Aug 2022 01:23:21 +0800 Subject: [PATCH 2/3] fix: alter imageEdit resizer test case data --- .../test/imageEdit/ResizerTest.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/roosterjs-editor-plugins/test/imageEdit/ResizerTest.ts b/packages/roosterjs-editor-plugins/test/imageEdit/ResizerTest.ts index 297bf430b72..00ed4a24b49 100644 --- a/packages/roosterjs-editor-plugins/test/imageEdit/ResizerTest.ts +++ b/packages/roosterjs-editor-plugins/test/imageEdit/ResizerTest.ts @@ -89,9 +89,9 @@ describe('Resizer: resize only', () => { s: [100, 220], }, e: { - n: [90, 180], + n: [120, 240], '': [120, 200], - s: [110, 220], + s: [120, 240], }, }); }); @@ -144,9 +144,9 @@ describe('Resizer: resize only', () => { s: [100, 207], }, e: { - n: [96, 192], + n: [127, 254], '': [127, 200], - s: [103, 207], + s: [127, 254], }, } ); From 86db80fbcc2a68fa10f38210e56740ec08d931a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=86=8A=E6=99=AF=E4=BC=9F?= <1054417359@qq.com> Date: Wed, 31 Aug 2022 11:10:55 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fix=EF=BC=9Awhen=20toggle=20list=20type,lis?= =?UTF-8?q?t=20symbol=20style=20maybe=20incorrect?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/list/setListItemStyle.ts | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/packages/roosterjs-editor-dom/lib/list/setListItemStyle.ts b/packages/roosterjs-editor-dom/lib/list/setListItemStyle.ts index ebb555c826e..0c1f4f6b561 100644 --- a/packages/roosterjs-editor-dom/lib/list/setListItemStyle.ts +++ b/packages/roosterjs-editor-dom/lib/list/setListItemStyle.ts @@ -12,7 +12,7 @@ import { InlineElement } from 'roosterjs-editor-types'; * @param styles The styles that should be applied to the element. */ export default function setListItemStyle(element: HTMLLIElement, styles: string[]) { - const elementsStyles = getInlineChildElementsStyle(element); + const elementsStyles = getInlineChildElementsStyle(element, styles); let stylesToApply: Record = getStyles(element); styles.forEach(styleName => { @@ -31,7 +31,7 @@ export default function setListItemStyle(element: HTMLLIElement, styles: string[ setStyles(element, stylesToApply); } -function getInlineChildElementsStyle(element: HTMLElement) { +function getInlineChildElementsStyle(element: HTMLElement, styles: string[]) { const result: Record[] = []; const contentTraverser = ContentTraverser.createBodyTraverser(element); let currentInlineElement: InlineElement | null = null; @@ -39,14 +39,31 @@ function getInlineChildElementsStyle(element: HTMLElement) { while (contentTraverser.currentInlineElement != currentInlineElement) { currentInlineElement = contentTraverser.currentInlineElement; let currentNode = currentInlineElement?.getContainerNode() || null; + const currentStyle: Record = {}; currentNode = currentNode ? findClosestElementAncestor(currentNode) : null; - if (safeInstanceOf(currentNode, 'HTMLElement')) { - let childStyle = getStyles(currentNode); - if (childStyle) { - result.push(childStyle); + + // we should consider of when it is the single childnode of element, the parentNode's style should add + // such as the "i", "b", "span" node in
  • aa
  • + while (currentNode && currentNode !== element && safeInstanceOf(currentNode, 'HTMLElement')) { + styles.forEach((styleName) => { + const styleValue = (currentNode as HTMLElement).style.getPropertyValue(styleName); + if (styleValue && !currentStyle[styleName]) { + currentStyle[styleName] = styleValue; + } + }); + + if (currentNode?.parentNode?.childNodes.length === 1) { + currentNode = currentNode.parentNode; + } else { + currentNode = null; } } + + if (currentStyle) { + result.push(currentStyle); + } + contentTraverser.getNextInlineElement(); }