refactoring

This commit is contained in:
Philipp Kühn 2021-01-28 09:57:20 +01:00
parent 4407d9a3d1
commit 6a5dde0101
5 changed files with 28 additions and 30 deletions

View File

@ -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,
}))]
})

View File

@ -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,

View File

@ -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,

View File

@ -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

View File

@ -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