Skip to content

Commit

Permalink
fix(addon-editor): support write simple text after marked link (#3021)
Browse files Browse the repository at this point in the history
  • Loading branch information
splincode authored Nov 7, 2022
1 parent 2afc420 commit a2f0123
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 6 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 @@ -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 a2f0123

Please sign in to comment.