Skip to content

Commit cd3cddd

Browse files
authored
fix(wysiwyg): dont apply wrapping input rules within non-default textblocks (#870)
1 parent 14bf513 commit cd3cddd

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

src/extensions/base/BaseSchema/BaseSchemaSpecs/index.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import type {NodeSpec} from 'prosemirror-model';
2-
3-
import {isEmptyString} from 'src/utils';
4-
5-
import type {ExtensionAuto} from '../../../../core';
6-
import {nodeTypeFactory} from '../../../../utils/schema';
1+
import type {ExtensionAuto} from '#core';
2+
import type {NodeSpec} from '#pm/model';
3+
import {isEmptyString} from 'src/utils/nodes';
4+
import {nodeTypeFactory} from 'src/utils/schema';
75

86
export enum BaseNode {
97
Doc = 'doc',

src/utils/inputrules.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import {InputRule} from 'prosemirror-inputrules';
22
import {Fragment, type Mark, type MarkType, type Node} from 'prosemirror-model';
33
import {type EditorState, TextSelection} from 'prosemirror-state';
44

5-
import {codeType} from '../extensions/markdown/specs';
6-
import {isFunction} from '../lodash';
7-
import {isMarkActive} from '../utils/marks';
8-
// TODO: remove explicit import from code extension
5+
// TODO: remove explicit import from base and code extensions
6+
import {pType} from 'src/extensions/base/specs';
7+
import {codeType} from 'src/extensions/markdown/specs';
8+
import {isFunction} from 'src/lodash';
9+
import {isMarkActive} from 'src/utils/marks';
910

1011
export function hasCodeMark(
1112
state: EditorState,
@@ -20,6 +21,15 @@ export function hasCodeMark(
2021
return false;
2122
}
2223

24+
export function inDefaultTextblock(
25+
state: EditorState,
26+
_match: RegExpMatchArray,
27+
start: number,
28+
_end: number,
29+
): boolean {
30+
return state.doc.resolve(start).parent.type === pType(state.schema);
31+
}
32+
2333
export {textblockTypeInputRule, wrappingInputRule} from './rulebuilders';
2434

2535
function getMarksBetween(start: number, end: number, state: EditorState) {

src/utils/rulebuilders.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {InputRule} from 'prosemirror-inputrules';
77
import type {Attrs, Node, NodeType} from 'prosemirror-model';
88
import {canJoin, findWrapping} from 'prosemirror-transform';
99

10-
import {hasCodeMark} from './inputrules';
10+
import {hasCodeMark, inDefaultTextblock} from './inputrules';
1111

1212
/// Build an input rule for automatically wrapping a textblock when a
1313
/// given string is typed. The `regexp` argument is
@@ -32,6 +32,7 @@ export function wrappingInputRule(
3232
) {
3333
return new InputRule(regexp, (state, match, start, end) => {
3434
if (hasCodeMark(state, match, start, end)) return null;
35+
if (!inDefaultTextblock(state, match, start, end)) return null;
3536

3637
const attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs;
3738
const tr = state.tr.delete(start, end);

0 commit comments

Comments
 (0)