mirror of
https://github.com/outline/outline.git
synced 2026-06-13 11:25:03 +03:00
abd7abcc18
* feat: table cell bgcolor * fix: review * fix: cleanup * fix: new color picker * fix: transparentize bg preset colors * fix: show selected color in color list * fix: pass active color to picker * fix: make color picker command agnostic * fix: tsc * fix: table row and col background menu * getColorSetForSelectedCells * toggleCellBackground to toggleCellSelectionBackground * cellHasBackground to cellSelectionHasBackground * useless spread * presetColors * get rid of hasMultipleColors * get rid of customColor * be explicit in passing color * alpha controls * remove new highligh command * DRY DottedCircleIcon * restore ff fix * merge createCellBackground into updateCelllBackground * default color * Merge --------- Co-authored-by: Tom Moor <tom@getoutline.com>
74 lines
1.9 KiB
TypeScript
74 lines
1.9 KiB
TypeScript
import type { NodeAttrMark } from "@shared/editor/types";
|
|
import type { ResolvedPos, MarkType } from "prosemirror-model";
|
|
import type { NodeSelection } from "prosemirror-state";
|
|
|
|
/**
|
|
* Returns the mark of type along with its range for a given ResolvedPos,
|
|
* or false if the mark is not found.
|
|
*
|
|
* @param $pos The ResolvedPos to check.
|
|
* @param type The MarkType to look for.
|
|
* @returns An object containing the from and to positions and the mark, or false.
|
|
*/
|
|
export function getMarkRange($pos?: ResolvedPos, type?: MarkType) {
|
|
if (!$pos || !type) {
|
|
return false;
|
|
}
|
|
|
|
const start = $pos.parent.childAfter($pos.parentOffset);
|
|
if (!start.node) {
|
|
return false;
|
|
}
|
|
|
|
const mark = start.node.marks.find((m) => m.type === type);
|
|
if (!mark) {
|
|
return false;
|
|
}
|
|
|
|
let startIndex = $pos.index();
|
|
let startPos = $pos.start() + start.offset;
|
|
let endIndex = startIndex + 1;
|
|
let endPos = startPos + start.node.nodeSize;
|
|
|
|
while (
|
|
startIndex > 0 &&
|
|
mark.isInSet($pos.parent.child(startIndex - 1).marks)
|
|
) {
|
|
startIndex -= 1;
|
|
startPos -= $pos.parent.child(startIndex).nodeSize;
|
|
}
|
|
|
|
while (
|
|
endIndex < $pos.parent.childCount &&
|
|
mark.isInSet($pos.parent.child(endIndex).marks)
|
|
) {
|
|
endPos += $pos.parent.child(endIndex).nodeSize;
|
|
endIndex += 1;
|
|
}
|
|
|
|
return { from: startPos, to: endPos, mark };
|
|
}
|
|
|
|
/**
|
|
* Returns the mark of type along with its range for a given NodeSelection,
|
|
* or false if the mark is not found.
|
|
*
|
|
* @param selection The NodeSelection to check.
|
|
* @param type The MarkType to look for.
|
|
* @returns An object containing the from and to positions and the mark, or false.
|
|
*/
|
|
export function getMarkRangeNodeSelection(
|
|
selection: NodeSelection,
|
|
type: MarkType
|
|
) {
|
|
const mark = (selection.node.attrs.marks ?? []).find(
|
|
(mark: NodeAttrMark) => mark.type === type.name
|
|
);
|
|
|
|
if (!mark) {
|
|
return false;
|
|
}
|
|
|
|
return { from: selection.from, to: selection.to, mark };
|
|
}
|