mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-01-18 06:03:22 +08:00
refactoring
This commit is contained in:
parent
4407d9a3d1
commit
6a5dde0101
@ -1,19 +1,13 @@
|
||||
import { Mark } from 'prosemirror-model'
|
||||
import { EditorState } from 'prosemirror-state'
|
||||
import { MarkRange } from '../types'
|
||||
|
||||
export type MarkPosition = {
|
||||
mark: Mark,
|
||||
start: number,
|
||||
end: number,
|
||||
}
|
||||
export default function getMarksBetween(from: number, to: number, state: EditorState): MarkRange[] {
|
||||
let marks: MarkRange[] = []
|
||||
|
||||
export default function getMarksBetween(start: number, end: number, state: EditorState): MarkPosition[] {
|
||||
let marks: MarkPosition[] = []
|
||||
|
||||
state.doc.nodesBetween(start, end, (node, pos) => {
|
||||
state.doc.nodesBetween(from, to, (node, pos) => {
|
||||
marks = [...marks, ...node.marks.map(mark => ({
|
||||
start: pos,
|
||||
end: pos + node.nodeSize,
|
||||
from: pos,
|
||||
to: pos + node.nodeSize,
|
||||
mark,
|
||||
}))]
|
||||
})
|
||||
|
@ -1,14 +1,8 @@
|
||||
import { EditorState } from 'prosemirror-state'
|
||||
import { Mark, MarkType } from 'prosemirror-model'
|
||||
import { MarkType } from 'prosemirror-model'
|
||||
import objectIncludes from '../utilities/objectIncludes'
|
||||
import getMarkType from './getMarkType'
|
||||
import { AnyObject } from '../types'
|
||||
|
||||
export type MarkRange = {
|
||||
mark: Mark,
|
||||
from: number,
|
||||
to: number,
|
||||
}
|
||||
import { AnyObject, MarkRange } from '../types'
|
||||
|
||||
export default function isMarkActive(
|
||||
state: EditorState,
|
||||
|
@ -1,14 +1,8 @@
|
||||
import { EditorState } from 'prosemirror-state'
|
||||
import { Node, NodeType } from 'prosemirror-model'
|
||||
import { NodeType } from 'prosemirror-model'
|
||||
import objectIncludes from '../utilities/objectIncludes'
|
||||
import getNodeType from './getNodeType'
|
||||
import { AnyObject } from '../types'
|
||||
|
||||
export type NodeRange = {
|
||||
node: Node,
|
||||
from: number,
|
||||
to: number,
|
||||
}
|
||||
import { AnyObject, NodeRange } from '../types'
|
||||
|
||||
export default function isNodeActive(
|
||||
state: EditorState,
|
||||
|
@ -24,7 +24,7 @@ export default function (regexp: RegExp, markType: MarkType, getAttributes?: Fun
|
||||
const { excluded } = item.mark.type
|
||||
return excluded.find((type: MarkType) => type.name === markType.name)
|
||||
})
|
||||
.filter(item => item.end > textStart)
|
||||
.filter(item => item.to > textStart)
|
||||
|
||||
if (excludedMarks.length) {
|
||||
return null
|
||||
|
@ -1,4 +1,8 @@
|
||||
import { Node as ProseMirrorNode, ParseOptions } from 'prosemirror-model'
|
||||
import {
|
||||
Node as ProseMirrorNode,
|
||||
Mark as ProseMirrorMark,
|
||||
ParseOptions,
|
||||
} from 'prosemirror-model'
|
||||
import {
|
||||
EditorView,
|
||||
Decoration,
|
||||
@ -138,4 +142,16 @@ export type Range = {
|
||||
to: number,
|
||||
}
|
||||
|
||||
export type NodeRange = {
|
||||
node: ProseMirrorNode,
|
||||
from: number,
|
||||
to: number,
|
||||
}
|
||||
|
||||
export type MarkRange = {
|
||||
mark: ProseMirrorMark,
|
||||
from: number,
|
||||
to: number,
|
||||
}
|
||||
|
||||
export type Predicate = (node: ProseMirrorNode) => boolean
|
||||
|
Loading…
Reference in New Issue
Block a user