Skip to content

Commit

Permalink
fix(link): while popup for link is open, box cannot be selected when …
Browse files Browse the repository at this point in the history
…clicking on it
  • Loading branch information
luolonghao committed Aug 30, 2024
1 parent 5da1d9f commit 542e581
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export class Editor {

private clickListener: EventListener = event => {
const targetNode = new Nodes(event.target as Element);
if (!targetNode.get(0).isConnected || targetNode.closest('.lake-popup').length > 0) {
if (!targetNode.get(0).isConnected) {
return;
}
this.event.emit('click', targetNode);
Expand Down
3 changes: 1 addition & 2 deletions src/plugins/format-painter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ export default (editor: Editor) => {
if (editor.container.contains(targetNode)) {
return;
}
const buttonNode = targetNode.closest('button[name="formatPainter"]');
if (buttonNode.length > 0) {
if (targetNode.closest('button[name="formatPainter"]').length > 0) {
return;
}
editor.container.removeClass(formatPainterClassName);
Expand Down
17 changes: 12 additions & 5 deletions src/plugins/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,22 @@ export default (editor: Editor) => {
popup.position();
});
editor.event.on('click', (targetNode: Nodes) => {
if (targetNode.closest('button[name="link"]').length > 0) {
if (popup.container.contains(targetNode)) {
return;
}
const linkNode = targetNode.closest('a');
if (linkNode.length === 0) {
popup.hide();
if (targetNode.closest('button[name="link"]').length > 0) {
return;
}
if (!editor.container.contains(linkNode) || linkNode.closest('lake-box').length > 0) {
const linkNode = targetNode.closest('a');
if (
linkNode.length === 0 ||
!editor.container.contains(linkNode) ||
linkNode.closest('lake-box').length > 0
) {
if (!popup.visible) {
return;
}
editor.selection.sync();
popup.hide();
return;
}
Expand Down
4 changes: 4 additions & 0 deletions src/ui/link-popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ export class LinkPopup {
button.render();
}

public get visible(): boolean {
return this.container.get(0).isConnected && this.container.computedCSS('display') !== 'none';
}

public getInputValue(name: string): string {
const inputElement = this.container.find(`input[name="${name}"]`);
const nativeInputElement = inputElement.get(0) as HTMLInputElement;
Expand Down
6 changes: 3 additions & 3 deletions tests/editor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ describe('editor', () => {
click(rootNode);
expect(clickCount).to.equal(1);
click(query(editor.popupContainer));
expect(clickCount).to.equal(1);
expect(clickCount).to.equal(2);
editor.unmount();
});

Expand All @@ -825,8 +825,8 @@ describe('editor', () => {
expect(clickCount).to.equal(1);
expect(clickCount2).to.equal(1);
click(query(editor.popupContainer));
expect(clickCount).to.equal(1);
expect(clickCount2).to.equal(1);
expect(clickCount).to.equal(2);
expect(clickCount2).to.equal(2);
editor.unmount();
editor2.unmount();
rootNode2.remove();
Expand Down

0 comments on commit 542e581

Please sign in to comment.