Skip to content

Commit

Permalink
fix: focus editor after inserting link or image
Browse files Browse the repository at this point in the history
  • Loading branch information
sibiraj-s committed Jan 8, 2021
1 parent ad2b19c commit 2d10e5f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/lib/commands/Image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ class Image {
nodeAttrs.width = selection.node.attrs.width;
}

tr.replaceSelectionWith(type.createAndFill(nodeAttrs));
tr
.replaceSelectionWith(type.createAndFill(nodeAttrs))
.scrollIntoView();

if (tr.docChanged) {
dispatch?.(tr);
Expand Down
12 changes: 10 additions & 2 deletions src/lib/commands/Link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,16 @@ class Link {


const node = schema.text(text, [schema.marks.link.create(attrs)]);
dispatch(tr.replaceSelectionWith(node, false));
return true;

tr.replaceSelectionWith(node, false)
.scrollIntoView();

if (tr.docChanged) {
dispatch?.(tr);
return true;
}

return false;
}

isActive(state: EditorState, options = defaultOptions): boolean {
Expand Down
1 change: 1 addition & 0 deletions src/lib/modules/menu/image/image.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export class ImageComponent implements OnDestroy {
};

ImageCommand.execute(attrs, state, dispatch);
this.editorView.focus();
this.hideForm();
}

Expand Down
1 change: 1 addition & 0 deletions src/lib/modules/menu/link/link.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export class LinkComponent implements OnDestroy {

if (selection.empty) {
LinkCommand.insert(text, attrs, state, dispatch);
this.editorView.focus();
} else {
LinkCommand.update(attrs, state, dispatch);
}
Expand Down

0 comments on commit 2d10e5f

Please sign in to comment.