Skip to content

Commit

Permalink
fix(addon-editor): support write simple text after marked link
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode committed Nov 7, 2022
1 parent 63c92d9 commit 166c09b
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ export class TuiToolbarComponent {

if (url) {
this.editor.toggleLink(url);
this.editor.selectClosest();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ export const defaultEditorExtensions = [
import(`@tiptap/extension-image`).then(({default: Image}) =>
Image.configure({inline: true}),
),
import(`@tiptap/extension-link`).then(({default: Link}) =>
Link.configure({openOnClick: false}),
),
import(`@taiga-ui/addon-editor/extensions/link`).then(({TuiLink}) => TuiLink),
import(`@taiga-ui/addon-editor/extensions/jump-anchor`).then(
({TuiJumpAnchor}) => TuiJumpAnchor,
),
Expand Down
1 change: 1 addition & 0 deletions projects/addon-editor/extensions/link/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './link';
38 changes: 38 additions & 0 deletions projects/addon-editor/extensions/link/link.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {getHTMLFromFragment} from '@tiptap/core';
import {Link} from '@tiptap/extension-link';

export const TuiLink = Link.extend({
addCommands() {
return {
...this.parent?.(),
toggleLink:
attributes =>
({chain, state}) => {
{
const {selection, doc} = state;
const selected = doc.cut(selection.to, selection.to + 1);
const sliced = getHTMLFromFragment(
selected.content,
state.schema,
).replace(/<\/?[^>]+(>|$)/g, ``);
const forwardSymbolIsWhitespace = sliced === ` `;

const toggleMark = chain().toggleMark(this.name, attributes, {
extendEmptyMarkRange: true,
});

return (
forwardSymbolIsWhitespace
? toggleMark.setTextSelection(selection.to + 1)
: toggleMark.setTextSelection(selection.to).insertContent(
// require: `@tiptap/extension-text-style`
`<span style="font-size: 15px"> </span>`,
)
).run();
}
},
};
},
}).configure({
openOnClick: false,
});
8 changes: 8 additions & 0 deletions projects/addon-editor/extensions/link/ng-package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"lib": {
"entryFile": "index.ts",
"styleIncludePaths": [
"../../../core/styles"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function tuiVisitEditorApiPage({
cy.viewport(1650, 900).tuiVisit(
`${EDITOR_PAGE_URL}/API?ngModel=${
content ?? HTML_EDITOR_BASIC_EXAMPLE
}&style.maxHeight.px=${maxHeight ?? 300}`,
}&style.maxHeight.px=${maxHeight ?? 500}`,
{
skipExpectUrl: true,
enableNightMode: enableNightMode ?? false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ describe(`Editing links in Editor`, () => {

tuiGetScreenshotArea().matchImageSnapshot(`3-1-before-remove-link`);

tuiOpenAnchorDropdown({containHref: `http://wysiwyg.com`});
tuiTrashValueByEditLink();

tuiClearHint();

tuiGetScreenshotArea().matchImageSnapshot(`3-2-after-remove-link`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ import {TUI_EDITOR_EXTENSIONS, TuiEditorTool} from '@taiga-ui/addon-editor';
({createImageEditorExtension}) =>
createImageEditorExtension(injector),
),
import(`@tiptap/extension-link`).then(({Link}) =>
Link.configure({openOnClick: false}),
import(`@tiptap/extension-text-style`).then(({TextStyle}) => TextStyle),
import(`@taiga-ui/addon-editor/extensions/link`).then(
({TuiLink}) => TuiLink,
),
import(`@taiga-ui/addon-editor/extensions/jump-anchor`).then(
({TuiJumpAnchor}) => TuiJumpAnchor,
Expand Down

0 comments on commit 166c09b

Please sign in to comment.