-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for checking for attributes in extendMarkRange
- Loading branch information
1 parent
5b8808a
commit ff7dd9b
Showing
7 changed files
with
391 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,20 @@ | ||
# extendMarkRange | ||
The `extendMarkRange` command expands the current selection to encompass the current mark. If the current selection doesn’t have the specified mark, nothing changes. | ||
|
||
<ContentMissing /> | ||
## Parameters | ||
`typeOrName: string | MarkType` | ||
|
||
Name or type of the mark. | ||
|
||
`attributes?: Record<string, any>` | ||
|
||
Optionally, you can specify attributes that the extented mark must contain. | ||
|
||
## Usage | ||
```js | ||
// Expand selection to link marks | ||
editor.commands.extendMarkRange('link') | ||
|
||
// Expand selection to link marks with specific attributes | ||
editor.commands.extendMarkRange('link', { href: 'https://google.com' }) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Node as ProseMirrorNode } from 'prosemirror-model' | ||
|
||
/** | ||
* Returns a node tree with node positions. | ||
*/ | ||
export default function getDebugJSON(node: ProseMirrorNode) { | ||
const debug = (startNode: ProseMirrorNode, startOffset = 0) => { | ||
const nodes: any[] = [] | ||
|
||
startNode.forEach((n, offset) => { | ||
const from = startOffset + offset | ||
const to = from + n.nodeSize | ||
|
||
nodes.push({ | ||
type: n.type.name, | ||
attrs: { ...n.attrs }, | ||
from, | ||
to, | ||
marks: n.marks.map(mark => ({ | ||
type: mark.type.name, | ||
attrs: { ...mark.attrs }, | ||
})), | ||
content: debug(n, from + 1), | ||
}) | ||
}) | ||
|
||
return nodes | ||
} | ||
|
||
return debug(node) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.