Files
outline/shared/editor/lib/listInputRule.ts
T
copilot-swe-agent[bot]andtommoor a38d10fbaa Add eslint-plugin-unused-imports with autofix support
- Install ESLint 9.x with TypeScript support
- Add eslint-plugin-unused-imports package
- Create eslint.config.mjs with flat config format
- Configure autofix for unused imports
- Update lint scripts to run ESLint with --fix flag
- Update lint-staged to run ESLint on staged files
- Add dedicated lint:eslint script for running only ESLint

Co-authored-by: tommoor <380914+tommoor@users.noreply.github.com>
2026-01-04 21:28:28 +00:00

34 lines
1.1 KiB
TypeScript

import { wrappingInputRule, InputRule } from "prosemirror-inputrules";
import type {
NodeType,
Node as ProsemirrorNode,
Attrs,
} from "prosemirror-model";
import { isInHeading } from "../queries/isInHeading";
/**
* A wrapper for wrappingInputRule that prevents execution inside heading nodes.
* This fixes the bug where typing list triggers ("* ", "- ", "1. ", etc.) inside
* a heading would trigger list conversion.
*/
export function listWrappingInputRule(
regexp: RegExp,
nodeType: NodeType,
getAttrs?: (match: RegExpMatchArray) => Attrs | null,
joinPredicate?: (match: RegExpMatchArray, node: ProsemirrorNode) => boolean
): InputRule {
const rule = wrappingInputRule(regexp, nodeType, getAttrs, joinPredicate);
// Wrap the original rule to check if we're inside a heading
return new InputRule(regexp, (state, match, start, end) => {
// Don't apply the rule if we're inside a heading
if (isInHeading(state)) {
return null;
}
// Otherwise, execute the original wrappingInputRule handler
return (rule as any).handler(state, match, start, end);
});
}