Skip to content

Commit 1dbf577

Browse files
committed
Fix: avoid sending unnecessary updates. Fixes failure in Client to move cursor.
1 parent 21135fe commit 1dbf577

File tree

2 files changed

+20
-24
lines changed

2 files changed

+20
-24
lines changed

client/src/CodeMirror-integration.mts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,6 @@ class DocBlockWidget extends WidgetType {
464464
// If this change was produced by a user edit, then the DOM was already
465465
// updated. Stop here.
466466
if (this.is_user_change) {
467-
console.log("user change -- skipping DOM update.");
468467
return true;
469468
}
470469
(dom.childNodes[0] as HTMLDivElement).innerHTML = this.indent;
@@ -676,7 +675,6 @@ const on_dirty = (
676675

677676
// Only run this after typesetting is done.
678677
window.MathJax.whenReady(async () => {
679-
console.log("Starting update for user change.");
680678
on_dirty_scheduled = false;
681679
// Find the doc block parent div.
682680
const target = (event_target as HTMLDivElement).closest(
@@ -1098,10 +1096,10 @@ export const CodeMirror_load = async (
10981096
setup: (editor: Editor) => {
10991097
// See the
11001098
// [docs](https://www.tiny.cloud/docs/tinymce/latest/events/#editor-core-events).
1101-
editor.on("Dirty", (event: any) => {
1099+
editor.on("input", (event: any) => {
11021100
// Get the div TinyMCE stores edits in. TODO: find
11031101
// documentation for `event.target.bodyElement`.
1104-
const target_or_false = event.target?.bodyElement;
1102+
const target_or_false = event.target as HTMLElement;
11051103
if (target_or_false == null) {
11061104
return false;
11071105
}

extensions/VSCode/src/extension.ts

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,14 @@ export const activate = (context: vscode.ExtensionContext) => {
163163
ignore_active_editor_change = false;
164164
return;
165165
}
166-
send_update(false);
166+
// Skip an update if we've already sent a `CurrentFile` for this editor.
167+
if (
168+
current_editor ===
169+
vscode.window.activeTextEditor
170+
) {
171+
return;
172+
}
173+
send_update(true);
167174
}),
168175
);
169176

@@ -174,6 +181,9 @@ export const activate = (context: vscode.ExtensionContext) => {
174181
ignore_selection_change = false;
175182
return;
176183
}
184+
console_log(
185+
"CodeChat Editor extension: sending updated cursor/scroll position.",
186+
);
177187
send_update(false);
178188
},
179189
),
@@ -246,19 +256,6 @@ export const activate = (context: vscode.ExtensionContext) => {
246256
webview_panel = undefined;
247257
await stop_client();
248258
});
249-
250-
// Render when the webview panel is shown.
251-
webview_panel.onDidChangeViewState(
252-
(
253-
_event: vscode.WebviewPanelOnDidChangeViewStateEvent,
254-
) => {
255-
// Only render if the webview was activated;
256-
// this event also occurs when it's deactivated.
257-
if (webview_panel?.active) {
258-
send_update(true);
259-
}
260-
},
261-
);
262259
}
263260
}
264261

@@ -367,6 +364,9 @@ export const activate = (context: vscode.ExtensionContext) => {
367364
await sendResult(id, "OutOfSync");
368365
// Send an `Update` with the full text to
369366
// re-sync the Client.
367+
console_log(
368+
"CodeChat Editor extension: sending update because Client is out of sync.",
369+
);
370370
send_update(true);
371371
break;
372372
}
@@ -395,10 +395,10 @@ export const activate = (context: vscode.ExtensionContext) => {
395395
}
396396
}
397397
}
398-
vscode.workspace.applyEdit(wse).then(() => {
399-
ignore_text_document_change = false;
400-
ignore_selection_change = false;
401-
});
398+
await vscode.workspace.applyEdit(wse);
399+
ignore_text_document_change = false;
400+
ignore_selection_change = false;
401+
402402
// Now that we've updated our text, update the
403403
// associated version as well.
404404
version = current_update.contents.version;
@@ -425,7 +425,6 @@ export const activate = (context: vscode.ExtensionContext) => {
425425
// viewport, but a bit below it.
426426
TextEditorRevealType.AtTop,
427427
);
428-
ignore_selection_change = false;
429428
}
430429

431430
let cursor_line = current_update.cursor_position;
@@ -443,7 +442,6 @@ export const activate = (context: vscode.ExtensionContext) => {
443442
cursor_position,
444443
),
445444
];
446-
ignore_selection_change = false;
447445
}
448446
await sendResult(id);
449447
break;

0 commit comments

Comments
 (0)