diff --git a/editors/editoria/src/config/config.js b/editors/editoria/src/config/config.js index 319094f1a7c8abbc3b3c5b71224b78a255949f01..6a29c0f794a50e5f6a3a00eb066093403b02ca58 100644 --- a/editors/editoria/src/config/config.js +++ b/editors/editoria/src/config/config.js @@ -71,9 +71,9 @@ export default { new TextBlockLevelService(), new TextToolGroupService(), new ListsService(), + new LinkService(), new TrackChangeService(), new CommentsService(), - new LinkService(), new PlaceholderService(), new ImageService(), new InlineAnnotationsService(), diff --git a/wax-prosemirror-components/src/components/link/LinkComponent.js b/wax-prosemirror-components/src/components/link/LinkComponent.js index c44c989fe393ce578cf4a4da3f3fc7b7810b8fcc..7fc43a202c8c296700f9298f65e1a0f19462e21c 100644 --- a/wax-prosemirror-components/src/components/link/LinkComponent.js +++ b/wax-prosemirror-components/src/components/link/LinkComponent.js @@ -43,6 +43,7 @@ const LinkComponent = ({ mark, setPosition, position }) => { const href = linkHref; const linkMark = state.schema.marks.link; const { tr } = state; + dispatch( tr.addMark( mark.from, @@ -86,7 +87,7 @@ const LinkComponent = ({ mark, setPosition, position }) => { const removeMarkIfEmptyHref = () => { const { selection: { $from, $to } } = state; const PMLinkMark = state.schema.marks["link"]; - const actualMark = DocumentHelpers.findMark(state, PMLinkMark); + const actualMark = DocumentHelpers.getSelectionMark(state, PMLinkMark); setLLastLinkMark(actualMark); if ( diff --git a/wax-prosemirror-components/src/components/trackChanges/TrackChangeBox.js b/wax-prosemirror-components/src/components/trackChanges/TrackChangeBox.js index 7c1fadeca38daa1a181cdd8451d51b748b1828d5..84d2d9b35d656ddc35ddfbf123369c003b5e85a2 100644 --- a/wax-prosemirror-components/src/components/trackChanges/TrackChangeBox.js +++ b/wax-prosemirror-components/src/components/trackChanges/TrackChangeBox.js @@ -28,7 +28,6 @@ const TrackChangeBoxStyled = styled.div` `; export default ({ trackChange, view, top, dataBox }) => { - console.log(trackChange); const [animate, setAnimate] = useState(false); const { view: { main }, app, activeView } = useContext(WaxContext); let action; diff --git a/wax-prosemirror-services/src/OverlayService/usePosition.js b/wax-prosemirror-services/src/OverlayService/usePosition.js index 9768d0aa241f85305d2d0ecde1503f02589a26a1..dc2738477299a21895b39f42f481d2bd2f82e668 100644 --- a/wax-prosemirror-services/src/OverlayService/usePosition.js +++ b/wax-prosemirror-services/src/OverlayService/usePosition.js @@ -55,7 +55,7 @@ export default options => { const displayOnMark = (activeView, options) => { const { markType, followCursor } = options; const PMmark = activeView.state.schema.marks[markType]; - mark = DocumentHelpers.findMark(activeView.state, PMmark); + mark = DocumentHelpers.getSelectionMark(activeView.state, PMmark); if (!isObject(mark)) return defaultOverlay; const { from, to } = followCursor ? activeView.state.selection : mark; diff --git a/wax-prosemirror-utilities/src/document/DocumentHelpers.js b/wax-prosemirror-utilities/src/document/DocumentHelpers.js index 37a09a354e27b5d3c0adbdf53b2d27df3c9060ab..1d9d80b9128eef96ed0f000222827dfd9cca4e4a 100644 --- a/wax-prosemirror-utilities/src/document/DocumentHelpers.js +++ b/wax-prosemirror-utilities/src/document/DocumentHelpers.js @@ -10,8 +10,8 @@ const findMark = (state, PMmark, toArr = false) => { const actualMark = node.marks.find(mark => mark.type === PMmark); if (actualMark) { markFound = { - from, - to: from + node.nodeSize, + from: $from.pos, + to: $to.pos, attrs: actualMark.attrs, contained: !fromMark || !toMark || fromMark === toMark }; @@ -23,6 +23,25 @@ const findMark = (state, PMmark, toArr = false) => { return markFound; }; +const getSelectionMark = (state, PMmark) => { + const { selection: { $from, $to }, doc } = state; + let markFound; + doc.nodesBetween($from.pos, $to.pos, (node, from) => { + if (node.marks) { + const actualMark = node.marks.find(mark => mark.type === PMmark); + if (actualMark) { + markFound = { + from: $from.pos, + to: $to.pos, + attrs: actualMark.attrs + }; + } + } + }); + + return markFound; +}; + export const flatten = (node, descend = true) => { if (!node) { throw new Error('Invalid "node" parameter'); @@ -72,5 +91,6 @@ export default { findChildrenByType, findInlineNodes, findChildrenByMark, - findChildrenByAttr + findChildrenByAttr, + getSelectionMark };