Skip to content
Snippets Groups Projects
Commit fb37b116 authored by chris's avatar chris
Browse files

Link creation fixed

parent c61f3d45
No related branches found
No related tags found
1 merge request!117Current features fixes
......@@ -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(),
......
......@@ -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 (
......
......@@ -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;
......
......@@ -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;
......
......@@ -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
};
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment