Skip to content

Commit

Permalink
fix #926
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Mar 8, 2021
1 parent f39c06f commit 2925923
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@

### v3.8.3 / 2021-02-xx

* [926](https://github.com/Vanessa219/vditor/issues/926) 即时渲染和所见即所得模式支持点击链接 `引入特性`

### v3.8.2 / 2021-03-01

* [938](https://github.com/Vanessa219/vditor/issues/938) 大纲缺少样式 `修复缺陷`
Expand Down
4 changes: 4 additions & 0 deletions src/assets/scss/_ir.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
padding: 0 !important;
}

&:not(.vditor-ir__node--expand)[data-type="a"] {
cursor: pointer;
}

&[data-type="link-ref"],
&[data-type="footnotes-ref"] {
color: $blurColor;
Expand Down
4 changes: 4 additions & 0 deletions src/assets/scss/_wysiwyg.scss
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@
white-space: initial;
}

a {
cursor: pointer;
}

span[data-type="backslash"] > span {
display: none;
color: var(--second-color);
Expand Down
10 changes: 8 additions & 2 deletions src/ts/ir/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
selectEvent,
} from "../util/editorCommonEvent";
import {paste} from "../util/fixBrowserBehavior";
import {hasClosestByClassName} from "../util/hasClosest";
import {hasClosestByAttribute, hasClosestByClassName} from "../util/hasClosest";
import {
getEditorRange, setRangeByWbr,
setSelectionFocus,
Expand Down Expand Up @@ -94,7 +94,7 @@ class IR {
this.preventInput = false;
return;
}
if (this.composingLock || event.data === "‘" || event.data === "“" || event.data === "《") {
if (this.composingLock || event.data === "‘" || event.data === "“" || event.data === "《") {
return;
}
input(vditor, getSelection().getRangeAt(0).cloneRange(), false, event);
Expand Down Expand Up @@ -141,6 +141,12 @@ class IR {
setSelectionFocus(range);
}
}
// 打开链接
const aElement = hasClosestByAttribute(event.target, "data-type", "a");
if (aElement && (!aElement.classList.contains("vditor-ir__node--expand"))) {
window.open(aElement.querySelector(":scope > .vditor-ir__marker--link").textContent);
return;
}

if (event.target.isEqualNode(this.element) && this.element.lastElementChild && range.collapsed) {
const lastRect = this.element.lastElementChild.getBoundingClientRect();
Expand Down
5 changes: 5 additions & 0 deletions src/ts/wysiwyg/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,11 @@ class WYSIWYG {
return;
}

// 打开链接
if (event.target.tagName === "A") {
window.open(event.target.getAttribute("href"));
}

const range = getEditorRange(vditor);
if (event.target.isEqualNode(this.element) && this.element.lastElementChild && range.collapsed) {
const lastRect = this.element.lastElementChild.getBoundingClientRect();
Expand Down

0 comments on commit 2925923

Please sign in to comment.