Skip to content
Snippets Groups Projects
Commit a2a3a3e9 authored by Christos's avatar Christos
Browse files

Merge branch 'link-command' into 'master'

fix commands for link (enable, updateHref)

See merge request !89
parents 3e52c2e6 f6c34e1a
No related branches found
No related tags found
1 merge request!89fix commands for link (enable, updateHref)
......@@ -39,12 +39,19 @@ const LinkComponent = ({ mark, setPosition, position }) => {
[ref.current, href]
);
const addLink = () => {
const addLinkHref = () => {
const href = linkHref;
const linkMark = state.schema.marks.link;
const { tr } = state;
dispatch(
state.tr
.removeMark(mark.from, mark.to, state.schema.marks.link)
.addMark(mark.from, mark.to, state.schema.marks.link.create({ href }))
tr.addMark(
mark.from,
mark.to,
linkMark.create({
...((mark && mark.attrs) || {}),
href
})
)
);
activeView.focus();
};
......@@ -56,11 +63,11 @@ const LinkComponent = ({ mark, setPosition, position }) => {
const handleKeyDown = event => {
if (event.key === "Enter" || event.which === 13) {
addLink();
addLinkHref();
}
};
const updateLink = () => {
const updateLinkHref = () => {
const { current: { value } } = linkInput;
setLinkHref(value);
};
......@@ -103,11 +110,11 @@ const LinkComponent = ({ mark, setPosition, position }) => {
<input
type="text"
ref={linkInput}
onChange={updateLink}
onChange={updateLinkHref}
onKeyPress={handleKeyDown}
value={linkHref}
/>
<Button primary onClick={addLink}>
<Button primary onClick={addLinkHref}>
{addButtonText}
</Button>
<Button onClick={removeLink}>Remove</Button>
......
......@@ -22,10 +22,7 @@ export default class LinkTool extends Tools {
get enable() {
return state => {
const { selection } = state;
const onSameNode = isEqual(selection.$from.path, selection.$to.path);
if (onSameNode && !selection.empty) return true;
return false;
return Commands.isOnSameTextBlock(state);
};
}
......
......@@ -59,6 +59,14 @@ const createLink = (state, dispatch) => {
);
};
const isOnSameTextBlock = state => {
const { selection: { $from, $to, from, to } } = state;
if (from !== to && $from.parent === $to.parent && $from.parent.isTextblock) {
return true;
}
return false;
};
const createComment = (state, dispatch, group) => {
const { selection: { $from, $to } } = state;
dispatch(
......@@ -75,10 +83,11 @@ const createComment = (state, dispatch, group) => {
};
export default {
markActive,
blockActive,
canInsert,
createTable,
createComment,
createLink,
createComment
createTable,
markActive,
isOnSameTextBlock
};
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