generated from Tinkoff/angular-open-source-starter
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: regression for anchor links (#1614)
- Loading branch information
Showing
12 changed files
with
3,008 additions
and
5,701 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const TUI_TIPTAP_WHITESPACE_HACK = `<span style="font-size: 15px"> </span>`; // require: `@tiptap/extension-text-style` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import type {Editor, Range} from '@tiptap/core'; | ||
|
||
export function tuiGetCurrentWordBounds(editor: Editor): Range { | ||
const {state} = editor; | ||
const {selection} = state; | ||
const {$anchor, empty} = selection; | ||
|
||
if (!empty) { | ||
return { | ||
from: selection.from, | ||
to: selection.to, | ||
}; | ||
} | ||
|
||
if ($anchor) { | ||
const {pos} = $anchor; | ||
const start = $anchor.start(); | ||
const parent = $anchor.parent; | ||
const textBefore = parent.textBetween(0, pos - start, undefined, `\uFFFC`); | ||
const textAfter = parent.textBetween( | ||
pos - start, | ||
parent.content.size, | ||
undefined, | ||
`\uFFFC`, | ||
); | ||
|
||
const wordBefore = textBefore | ||
// eslint-disable-next-line unicorn/prefer-string-replace-all | ||
.replaceAll(/\uFFFC/g, ``) | ||
.split(/\b/) | ||
.pop(); | ||
const wordAfter = textAfter | ||
// eslint-disable-next-line unicorn/prefer-string-replace-all | ||
.replaceAll(/\uFFFC/g, ``) | ||
.split(/\b/) | ||
.shift(); | ||
|
||
const from = pos - (wordBefore?.length ?? 0); | ||
const to = pos + (wordAfter?.length ?? 0); | ||
|
||
return { | ||
from, | ||
to, | ||
}; | ||
} | ||
|
||
return { | ||
from: selection.to, | ||
to: selection.to + 1, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import {getHTMLFromFragment} from '@tiptap/core'; | ||
import type {EditorState} from '@tiptap/pm/state'; | ||
|
||
export function tuiGetSlicedFragment(state: EditorState, to: number): string { | ||
const {doc, schema} = state; | ||
const selected = doc.cut(to, to + 1); | ||
|
||
return getHTMLFromFragment(selected.content, schema).replaceAll( | ||
/<\/?[^>]+(>|$)/g, | ||
``, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters