Skip to content

Commit d9c3310

Browse files
authored
Fix open link stop running (#189)
1 parent e2fc460 commit d9c3310

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

editor/commentLink.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ export const commentLinkClickHandler = EditorView.domEventHandlers({
7575
if (!url) return false;
7676
if (event.metaKey || event.ctrlKey) {
7777
event.preventDefault();
78+
// Notify the runtime to resume running.
79+
window.dispatchEvent(new Event("openlink"));
7880
window.open(url, "_blank", "noopener,noreferrer");
7981
return true;
8082
}

editor/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export function createEditor(container, options) {
8888
runtimeRef.current.onChanges(dispatch);
8989
window.addEventListener("keydown", onKeyDown);
9090
window.addEventListener("keyup", onKeyUp);
91+
window.addEventListener("openlink", onOpenLink);
9192
}
9293

9394
function dispatch(changes) {
@@ -131,6 +132,12 @@ export function createEditor(container, options) {
131132
}
132133
}
133134

135+
function onOpenLink() {
136+
if (!isStopByMetaKey) return;
137+
isStopByMetaKey = false;
138+
runtimeRef.current?.setIsRunning(true);
139+
}
140+
134141
return {
135142
run: () => {
136143
try {
@@ -146,12 +153,14 @@ export function createEditor(container, options) {
146153
runtimeRef.current = null;
147154
window.removeEventListener("keydown", onKeyDown);
148155
window.removeEventListener("keyup", onKeyUp);
156+
window.removeEventListener("openlink", onOpenLink);
149157
},
150158
on: (event, callback) => dispatcher.on(event, callback),
151159
destroy: () => {
152160
runtimeRef.current?.destroy();
153161
window.removeEventListener("keydown", onKeyDown);
154162
window.removeEventListener("keyup", onKeyUp);
163+
window.removeEventListener("openlink", onOpenLink);
155164
view.destroy();
156165
},
157166
};

0 commit comments

Comments
 (0)