Skip to content

Fix extra list indentation when pasting from Word Desktop#3330

Merged
BryanValverdeU merged 6 commits intomasterfrom
u/bvalverde/pasteWord1
Apr 29, 2026
Merged

Fix extra list indentation when pasting from Word Desktop#3330
BryanValverdeU merged 6 commits intomasterfrom
u/bvalverde/pasteWord1

Conversation

@BryanValverdeU
Copy link
Copy Markdown
Contributor

When pasting from Word Desktop, Word's global stylesheet includes margin declarations on p.MsoListParagraph, div.MsoListParagraph, and their CxSpFirst/Middle/Last variants. These global CSS rules were being applied as inline styles before RoosterJS processed the list structure, causing double-indentation on pasted lists.

  • Add globalCssRules to BeforePasteEvent and promote CssRule to a public type in roosterjs-content-model-types
  • Pass globalCssRules into the BeforePasteEvent from generatePasteOptionFromPlugins
  • Add removeListParagraphMargins.ts which strips margin-* properties from global CSS rules targeting the Word list paragraph classes; mixed-selector rules are split so only the matching selectors lose their margins
  • Wire removeListParagraphMargins into processPastedContentFromWordDesktop via a new globalCssRules parameter, passed through from PastePlugin

BryanValverdeU and others added 2 commits April 28, 2026 17:35
When pasting from Word Desktop, Word's global stylesheet includes margin
declarations on p.MsoListParagraph, div.MsoListParagraph, and their
CxSpFirst/Middle/Last variants. These global CSS rules were being applied
as inline styles before RoosterJS processed the list structure, causing
double-indentation on pasted lists.

- Add globalCssRules to BeforePasteEvent and promote CssRule to a public
  type in roosterjs-content-model-types
- Pass globalCssRules into the BeforePasteEvent from generatePasteOptionFromPlugins
- Add removeListParagraphMargins.ts which strips margin-* properties from
  global CSS rules targeting the Word list paragraph classes; mixed-selector
  rules are split so only the matching selectors lose their margins
- Wire removeListParagraphMargins into processPastedContentFromWordDesktop
  via a new globalCssRules parameter, passed through from PastePlugin
- Set browser in karma client config so itChromeOnly works correctly with
  the fast config

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses double-indentation on lists pasted from Word Desktop by preventing Word’s global CSS margins (for p/div.MsoListParagraph*) from being inlined before RoosterJS list processing.

Changes:

  • Promotes CssRule to a public type and adds globalCssRules to BeforePasteEvent, then threads globalCssRules through the paste pipeline.
  • Adds removeListParagraphMargins to strip margin* properties from Word list-paragraph global CSS rules (splitting mixed-selector rules as needed).
  • Updates Word Desktop paste processing to apply the new global CSS rule sanitization and adds/updates unit tests.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/roosterjs-content-model-types/lib/index.ts Re-exports CssRule from types entrypoint for consumers.
packages/roosterjs-content-model-types/lib/event/BeforePasteEvent.ts Adds CssRule type + globalCssRules field on BeforePasteEvent.
packages/roosterjs-content-model-plugins/lib/paste/WordDesktop/removeListParagraphMargins.ts New helper that removes margin properties from Word list-paragraph CSS rules.
packages/roosterjs-content-model-plugins/lib/paste/WordDesktop/processPastedContentFromWordDesktop.ts Wires removeListParagraphMargins into Word Desktop paste handling via new globalCssRules param.
packages/roosterjs-content-model-plugins/lib/paste/PastePlugin.ts Passes event.globalCssRules into Word Desktop processing.
packages/roosterjs-content-model-core/lib/command/paste/generatePasteOptionFromPlugins.ts Populates BeforePasteEvent.globalCssRules from retrieveHtmlInfo.
packages/roosterjs-content-model-core/lib/command/paste/retrieveHtmlInfo.ts Uses the shared CssRule type and returns extracted globalCssRules.
packages/roosterjs-content-model-core/lib/command/createModelFromHtml/convertInlineCss.ts Switches to importing CssRule from roosterjs-content-model-types.
packages/roosterjs-content-model-core/test/command/paste/generatePasteOptionFromPluginsTest.ts Updates expectations to include globalCssRules.
packages/roosterjs-content-model-plugins/test/paste/word/removeListParagraphMarginsTest.ts Adds unit coverage for margin-stripping behavior (including mixed-selector splitting).
packages/roosterjs-content-model-plugins/test/paste/word/processPastedContentFromWordDesktopTest.ts Updates test harness to pass CSS rules into Word Desktop processor.
CLAUDE.md Adds reference to AGENTS.md.
AGENTS.md Adds repo guidance (architecture + commands).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

selectors: string[];
text: string;
}
import type { CssRule } from 'roosterjs-content-model-types';
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

convertInlineCss.ts used to export a CssRule interface, but this change removes that export. There are existing imports (e.g. unit tests and potentially downstream internal code) that import CssRule from this module, which will now fail to compile. To preserve compatibility, re-export the new public CssRule type from roosterjs-content-model-types (type-only export) or update all import sites in the repo accordingly.

Suggested change
import type { CssRule } from 'roosterjs-content-model-types';
import type { CssRule } from 'roosterjs-content-model-types';
export type { CssRule } from 'roosterjs-content-model-types';

Copilot uses AI. Check for mistakes.
@BryanValverdeU BryanValverdeU enabled auto-merge (squash) April 29, 2026 14:47
@BryanValverdeU BryanValverdeU merged commit b31be99 into master Apr 29, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants