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

Content Model: Reorganize some code #1973

Merged
merged 3 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Expand Up @@ -4,7 +4,7 @@ import { addSelectionMarker } from '../utils/addSelectionMarker';
import { areSameFormats } from '../utils/areSameFormats';
import { createText } from '../../modelApi/creators/createText';
import { getRegularSelectionOffsets } from '../utils/getRegularSelectionOffsets';
import { hasSpacesOnly } from '../../domUtils/stringUtil';
import { hasSpacesOnly } from '../../modelApi/common/hasSpacesOnly';
import {
ContentModelBlockGroup,
DomToModelContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,4 @@ export { parseValueWithUnit } from './formatHandlers/utils/parseValueWithUnit';
export { BorderKeys } from './formatHandlers/common/borderFormatHandler';
export { defaultImplicitFormatMap } from './formatHandlers/utils/defaultStyles';

export { isPunctuation, isSpace, normalizeText } from './domUtils/stringUtil';

export { createDomToModelContext } from './domToModel/context/createDomToModelContext';
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// A regex to match text that only has space and CR
// We use real space char " " (\u0020) here but not "\s" since "\s" will also match " " (\u00A0) which is something we need to keep
const SPACE_TEXT_REGEX = /^[\r\n\t ]*$/;

/**
* @internal
* Check if the given string only has space, including line breaks.
* @param txt The string to check
*/
export function hasSpacesOnly(txt: string): boolean {
return SPACE_TEXT_REGEX.test(txt);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { hasSpacesOnly } from '../../lib/domUtils/stringUtil';
import { hasSpacesOnly } from '../../../lib/modelApi/common/hasSpacesOnly';

describe('hasSpacesOnly', () => {
it('Empty string', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { hasSpacesOnly } from '../../domUtils/stringUtil';
import { hasSpacesOnly } from './hasSpacesOnly';
import {
ContentModelParagraph,
ContentModelSegment,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
// A regex to match text that only has space and CR
// We use real space char " " (\u0020) here but not "\s" since "\s" will also match " " (\u00A0) which is something we need to keep
const SPACE_TEXT_REGEX = /^[\r\n\t ]*$/;

const SPACES_REGEX = /[\u2000\u2009\u200a​\u200b​\u202f\u205f​\u3000\s\t\r\n]/gm;
const PUNCTUATIONS = '.,?!:"()[]\\/';

/**
* @internal
* Check if the given character is punctuation
* @param char The character to check
*/
Expand All @@ -14,6 +11,7 @@ export function isPunctuation(char: string) {
}

/**
* @internal
* Check if the give character is a space. A space can be normal ASCII pace (32) or non-break space (160) or other kinds of spaces
* such as ZeroWidthSpace, ...
* @param char The character to check
Expand All @@ -25,14 +23,6 @@ export function isSpace(char: string) {

/**
* @internal
* Check if the given string only has space, including line breaks.
* @param txt The string to check
*/
export function hasSpacesOnly(txt: string): boolean {
return SPACE_TEXT_REGEX.test(txt);
}

/**
* Normalize spaces of the given string. After normalization, all leading (for forward) or trailing (for backward) spaces
* will be replaces with non-break space (160)
* @param txt The string to normalize
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { ContentModelParagraph } from 'roosterjs-content-model-types';
import {
isPunctuation,
isSpace,
isWhiteSpacePreserved,
normalizeText,
} from 'roosterjs-content-model-dom';
import { isPunctuation, isSpace, normalizeText } from '../../../domUtils/stringUtil';
import { isWhiteSpacePreserved } from 'roosterjs-content-model-dom';
import {
DeleteResult,
DeleteSelectionContext,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { ContentModelParagraph, ContentModelSegment } from 'roosterjs-content-model-types';
import { deleteSingleChar } from './deleteSingleChar';
import { EntityOperation } from 'roosterjs-editor-types';
import { isWhiteSpacePreserved, normalizeSingleSegment } from 'roosterjs-content-model-dom';
import { normalizeText } from '../../../domUtils/stringUtil';
import { OnDeleteEntity } from './DeleteSelectionStep';
import {
isWhiteSpacePreserved,
normalizeSingleSegment,
normalizeText,
} from 'roosterjs-content-model-dom';

/**
* @internal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createText, isPunctuation, isSpace } from 'roosterjs-content-model-dom';
import { createText } from 'roosterjs-content-model-dom';
import { isPunctuation, isSpace } from '../../domUtils/stringUtil';
import { iterateSelections } from '../../modelApi/selection/iterateSelections';
import {
ContentModelDocument,
Expand Down

Large diffs are not rendered by default.