editor: handle link open on click

This commit is contained in:
Abdullah Atta
2024-03-18 12:09:03 +05:00
parent 61e0fdea50
commit b4161644d0
2 changed files with 8 additions and 4 deletions

View File

@@ -17,12 +17,13 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { getAttributes } from "@tiptap/core";
import { Editor, getAttributes } from "@tiptap/core";
import { MarkType } from "@tiptap/pm/model";
import { Plugin, PluginKey } from "@tiptap/pm/state";
type ClickHandlerOptions = {
type: MarkType;
editor: Editor;
};
export function clickHandler(options: ClickHandlerOptions): Plugin {
@@ -50,10 +51,12 @@ export function clickHandler(options: ClickHandlerOptions): Plugin {
const link = event.target as HTMLLinkElement;
const href = link?.href ?? attrs.href;
const target = link?.target ?? attrs.target;
// const target = link?.target ?? attrs.target;
if (link && href) {
if (view.editable) window.open(href, target);
if (view.editable) {
options.editor.storage.openLink?.(href);
}
return true;
}

View File

@@ -273,7 +273,8 @@ export const Link = Mark.create<LinkOptions>({
if (this.options.openOnClick) {
plugins.push(
clickHandler({
type: this.type
type: this.type,
editor: this.editor
})
);
}