Skip to content

Commit

Permalink
Merge branch 'fix/link_not_work_in_firefox' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Leecason committed Jun 20, 2020
2 parents 5616818 + f286d5c commit 2cc8d0d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 18 deletions.
11 changes: 11 additions & 0 deletions src/components/MenuCommands/Link/AddLinkCommandButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,24 @@ export default class AddLinkCommandButton extends Mixins(i18nMixin) {
@Inject() readonly editorStateOptions!: EditorStateOptions;
openApplyLinkControl (): void {
const { editor } = this.editorContext;
const { state, view } = editor;
const { tr } = state; // current trascation, need to restore when confirmed
MessageBox.prompt('', this.t('editor.extensions.Link.add.control.title'), {
confirmButtonText: this.t('editor.extensions.Link.add.control.confirm'),
cancelButtonText: this.t('editor.extensions.Link.add.control.cancel'),
inputPlaceholder: this.t('editor.extensions.Link.add.control.placeholder'),
roundButton: true,
// @ts-ignore
}).then(({ value: href }) => {
// https://github.com/Leecason/element-tiptap/issues/119
// in Firefox 77, when message-box confirm button clicked, editor will lose focus
// and re-focus on closeDialog's next tick, https://github.com/ElemeFE/element/blob/dev/src/utils/aria-dialog.js#L66
// but re-focus will lose the previous selection, so add link will not work
// here need to restore the previous trascation
view.dispatch(tr);
this.editorContext.commands.link({ href });
}).catch(() => {
Expand Down
11 changes: 11 additions & 0 deletions src/components/MenuCommands/Link/EditLinkCommandButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ export default class EditLinkCommandButton extends Mixins(i18nMixin) {
readonly initUrl!: string;
openEditLinkControl (): void {
const { editor } = this.editorContext;
const { state, view } = editor;
const { tr } = state; // current trascation, need to restore when confirmed
MessageBox.prompt('', this.t('editor.extensions.Link.edit.control.title'), {
confirmButtonText: this.t('editor.extensions.Link.edit.control.confirm'),
cancelButtonText: this.t('editor.extensions.Link.edit.control.cancel'),
Expand All @@ -40,6 +44,13 @@ export default class EditLinkCommandButton extends Mixins(i18nMixin) {
roundButton: true,
// @ts-ignore
}).then(({ value: href }) => {
// https://github.com/Leecason/element-tiptap/issues/119
// in Firefox 77, when message-box confirm button clicked, editor will lose focus
// and re-focus on closeDialog's next tick, https://github.com/ElemeFE/element/blob/dev/src/utils/aria-dialog.js#L66
// but re-focus will lose the previous selection, so add link will not work
// here need to restore the previous trascation
view.dispatch(tr);
this.editorContext.commands.link({ href });
}).catch(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/MenuCommands/Link/UnlinkCommandButton.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<command-button
:command="editorContext.commands.unlink"
:command="() => editorContext.commands.link({ href: '' })"
:tooltip="t('editor.extensions.Link.unlink.tooltip')"
icon="unlink"
/>
Expand Down
17 changes: 0 additions & 17 deletions src/extensions/link.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,12 @@
import { MarkType } from 'prosemirror-model';
import { Plugin, TextSelection } from 'prosemirror-state';
import { Link as TiptapLink } from 'tiptap-extensions';
// @ts-ignore
import { updateMark, removeMark, CommandFunction } from 'tiptap-commands';
// @ts-ignore
import { getMarkRange } from 'tiptap-utils';
import { MenuData } from 'tiptap';
import { MenuBtnView } from '@/../types';
import AddLinkCommandButton from '@/components/MenuCommands/Link/AddLinkCommandButton.vue';

export default class Link extends TiptapLink implements MenuBtnView {
commands ({ type }: { type: MarkType }) {
return {
link: (attrs: { href: string }) => {
if (attrs.href) {
return updateMark(type, attrs);
}

return removeMark(type);
},

unlink: (): CommandFunction => removeMark(type),
};
}

get plugins () {
return [
new Plugin({
Expand Down

0 comments on commit 2cc8d0d

Please sign in to comment.