Skip to content

Commit

Permalink
chore: simplify selection params
Browse files Browse the repository at this point in the history
  • Loading branch information
sibiraj-s committed Nov 29, 2020
1 parent 38c47f5 commit 5bf6731
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/plugins/menu/items/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ const link = (view: EditorView, spec: MenuItemSpec): MenuItemViewRender => {

const onPopupOpen = () => {
const { state } = view;
const { doc, selection: { from, to, empty }, schema } = state;
const { doc, selection, schema } = state;
const { from, to, empty } = selection;
const isActive = isMarkActive(state, schema.marks.link);

if (isActive) {
Expand All @@ -72,9 +73,11 @@ const link = (view: EditorView, spec: MenuItemSpec): MenuItemViewRender => {

const selectedText = !empty ? doc.textBetween(from, to) : '';

const nodeSelection = state.selection as NodeSelection;
const isImageNode = nodeSelection.node?.type.name === 'image';
const isTextDisabled = isImageNode ?? false;
let isTextDisabled = false;

if (selection instanceof NodeSelection) {
isTextDisabled = selection.node.type.name === 'image';
}

renderForm(getFormInputs(selectedText, isTextDisabled));
return true;
Expand Down

0 comments on commit 5bf6731

Please sign in to comment.