mirror of
https://github.com/outline/outline.git
synced 2026-11-23 06:11:04 +03:00
* fix: port link related commands to work for image selection
* fix: selection
* fix: click img to open link
* fix: hover preview for image with link
* cleanup: hasLink not needed
* fix: we've img wrapped in an `a` tag now, so this is no more required
* fix: cover all edge cases
* fix: cleanup
* fix: zoom in action button in edit mode
* fix: separator div instead of gap
* fix: toolbar refactor
* fix: back button press
* fix: import
* fix: revert
* fix: enum
* fix: onClick on item
* fix: selection at end after link
* fix: show linkbar if link present
* fix: ReturnIcon
* fix: onClickBack
* fix: TOOLBAR -> Toolbar
* fix: show zoom in icon even when selected
* fix: isInlineMarkActive
* fix: jsdoc
* yarn.lock
* Revert "yarn.lock"
This reverts commit 5f44e5e017.
* fix: yarn.lock
* fix: link editor closes upon zoom in click action
* Update shared/editor/queries/isMarkActive.ts
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update shared/editor/queries/getMarkRange.ts
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update shared/editor/components/Image.tsx
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update app/editor/components/LinkEditor.tsx
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* fix: prevent toolbar state reset
* fix: tooltip
* fix: copilot
* fix: i18n, misuse of attrs
---------
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Tom Moor <tom@getoutline.com>
74 lines
1.9 KiB
TypeScript
74 lines
1.9 KiB
TypeScript
import { NodeMarkAttr } from "@shared/editor/types";
|
|
import { ResolvedPos, MarkType } from "prosemirror-model";
|
|
import { 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: NodeMarkAttr) => mark.type === type.name
|
|
);
|
|
|
|
if (!mark) {
|
|
return false;
|
|
}
|
|
|
|
return { from: selection.from, to: selection.to, mark };
|
|
}
|