1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-28 17:02:04 +03:00

Shared link mark update logic with color controls

This commit is contained in:
Dan Brown
2022-01-19 23:54:59 +00:00
parent bb12541179
commit b1f5495a7f
3 changed files with 48 additions and 17 deletions

View File

@ -6,7 +6,7 @@ import schema from "../schema";
import {MenuItem} from "./menu";
import {icons} from "./icons";
import {markRangeAtPosition, nullifyEmptyValues} from "../util";
import {expandSelectionToMark, nullifyEmptyValues} from "../util";
/**
* @param {PmMarkType} markType
@ -74,17 +74,7 @@ function applyLink(formData, state, dispatch) {
if (!dispatch) return true;
const tr = state.tr;
const noRange = (selection.from - selection.to === 0);
let from = selection.from;
let to = selection.to;
if (noRange) {
const linkRange = markRangeAtPosition(state, schema.marks.link, selection.from);
if (linkRange.from !== -1) {
from = linkRange.from;
to = linkRange.to;
}
}
const {from, to} = expandSelectionToMark(state, selection, schema.marks.link);
if (attrs.href) {
tr.addMark(from, to, schema.marks.link.create(attrs));