Skip to content

Commit 7da44a7

Browse files
authored
fix: skip completing placeholder on readonly editors (#5661)
Skip completing placeholder when the editor is readonly
1 parent 76aadfb commit 7da44a7

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

frontend/src/core/codemirror/placeholder/extensions.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* Copyright 2024 Marimo. All rights reserved. */
22
import type { Extension } from "@codemirror/state";
33
import { EditorView, keymap, placeholder } from "@codemirror/view";
4+
import { isEditorReadonly } from "../readonly/extension";
45

56
/**
67
* A placeholder that will be shown when the editor is empty and support
@@ -25,6 +26,10 @@ export function smartPlaceholderExtension(text: string): Extension[] {
2526
}
2627

2728
function acceptPlaceholder(cm: EditorView, text: string) {
29+
if (isEditorReadonly(cm.state)) {
30+
return false;
31+
}
32+
2833
// if empty, insert the placeholder
2934
const docLength = cm.state.doc.length;
3035
if (docLength === 0) {

frontend/src/core/codemirror/readonly/extension.test.ts renamed to frontend/src/core/codemirror/readonly/__tests__/extension.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { EditorView } from "@codemirror/view";
55
import { createStore } from "jotai";
66
import { describe, expect, it } from "vitest";
77
import { WebSocketState } from "@/core/websocket/types";
8-
import { connectionAtom } from "../../network/connection";
9-
import { dynamicReadonly, isEditorReadonly } from "./extension";
8+
import { connectionAtom } from "../../../network/connection";
9+
import { dynamicReadonly, isEditorReadonly } from "../extension";
1010

1111
function makeStoreWithConnection(
1212
state: WebSocketState.CONNECTING | WebSocketState.OPEN,

frontend/src/core/network/requests-network.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
import { once } from "lodash-es";
44
import { getRuntimeManager } from "../runtime/config";
5+
import { store } from "../state/jotai";
56
import { API, createClientWithRuntimeManager } from "./api";
6-
import { waitForConnectionOpen } from "./connection";
7+
import { isConnectedAtom, waitForConnectionOpen } from "./connection";
78
import type { EditRequests, RunRequests } from "./types";
89

910
const { handleResponse, handleResponseReturnNull } = API;
@@ -83,7 +84,11 @@ export function createNetworkRequests(): EditRequests & RunRequests {
8384
.then(handleResponseReturnNull);
8485
},
8586
sendRun: async (request) => {
86-
await waitForConnectionOpen();
87+
// Rather than waiting, we just drop all sendRun requests if the connection is not open.
88+
// Otherwise we can get into a weird state of sending requests for cells that no longer exist.
89+
if (!store.get(isConnectedAtom)) {
90+
return null;
91+
}
8792
return getClient()
8893
.POST("/api/kernel/run", {
8994
body: request,

0 commit comments

Comments
 (0)