mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-02-24 04:00:59 +01:00
editor: handle link open on click
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user