-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
feat: #3540 Ability to preserve marks on lists #3541
Changes from 2 commits
ad70224
73c96f5
9161e1e
0ee1515
f82c85c
50b95b9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
import { mergeAttributes, Node, wrappingInputRule } from '@tiptap/core' | ||
|
||
import ListItem from '../../extension-list-item/src' | ||
import TextStyle from '../../extension-text-style/src' | ||
|
||
export interface OrderedListOptions { | ||
itemTypeName: string, | ||
HTMLAttributes: Record<string, any>, | ||
keepMarks: boolean, | ||
keepAttributes: boolean, | ||
} | ||
|
||
declare module '@tiptap/core' { | ||
|
@@ -25,6 +30,8 @@ export const OrderedList = Node.create<OrderedListOptions>({ | |
return { | ||
itemTypeName: 'listItem', | ||
HTMLAttributes: {}, | ||
keepMarks: false, | ||
keepAttributes: false, | ||
} | ||
}, | ||
|
||
|
@@ -65,7 +72,10 @@ export const OrderedList = Node.create<OrderedListOptions>({ | |
|
||
addCommands() { | ||
return { | ||
toggleOrderedList: () => ({ commands }) => { | ||
toggleOrderedList: () => ({ commands, chain }) => { | ||
if (this.options.keepAttributes) { | ||
return chain().toggleList(this.name, this.options.itemTypeName).updateAttributes(ListItem.name, this.editor.getAttributes(TextStyle.name)).run() | ||
} | ||
return commands.toggleList(this.name, this.options.itemTypeName) | ||
}, | ||
} | ||
|
@@ -78,13 +88,23 @@ export const OrderedList = Node.create<OrderedListOptions>({ | |
}, | ||
|
||
addInputRules() { | ||
return [ | ||
wrappingInputRule({ | ||
let inputRule = wrappingInputRule({ | ||
find: inputRegex, | ||
type: this.type, | ||
}) | ||
|
||
if (this.options.keepMarks || this.options.keepAttributes) { | ||
inputRule = wrappingInputRule({ | ||
find: inputRegex, | ||
type: this.type, | ||
getAttributes: match => ({ start: +match[1] }), | ||
joinPredicate: (match, node) => node.childCount + node.attrs.start === +match[1], | ||
Comment on lines
-85
to
-86
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe these removed lines broke support for creating ordered lists with a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
}), | ||
keepMarks: this.options.keepMarks, | ||
keepAttributes: this.options.keepAttributes, | ||
getAttributes: () => { return this.editor.getAttributes(TextStyle.name) }, | ||
editor: this.editor, | ||
}) | ||
} | ||
return [ | ||
inputRule, | ||
] | ||
}, | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bdbch I'm just worried about this piece of code, please let me know if there's any better way of doing this. The idea here is
<li>
only then it is color is also applied for thelist-style
indicator.