Skip to content

Commit 510bad3

Browse files
committed
Fix: allow external edits when the Client has focus.
1 parent 60eb82f commit 510bad3

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

extensions/VSCode/src/extension.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -577,11 +577,10 @@ export const deactivate = async () => {
577577
// Format a complex data structure as a string when in debug mode.
578578
const format_struct = (complex_data_structure: any): string =>
579579
DEBUG_ENABLED
580-
// If the struct is `undefined`, print an empty string.
581-
? JSON.stringify(complex_data_structure ?? "").substring(
582-
0,
583-
MAX_MESSAGE_LENGTH,
584-
)
580+
? JSON.stringify(
581+
// If the struct is `undefined`, print an empty string.
582+
complex_data_structure ?? "",
583+
).substring(0, MAX_MESSAGE_LENGTH)
585584
: "";
586585

587586
// Send a result (a response to a message from the server) back to the server.
@@ -613,8 +612,8 @@ const send_update = (this_is_dirty: boolean) => {
613612
// ... schedule a render after an autosave timeout.
614613
idle_timer = setTimeout(async () => {
615614
if (can_render()) {
616-
const ate = vscode.window.activeTextEditor!;
617-
if (ate !== current_editor) {
615+
const ate = vscode.window.activeTextEditor;
616+
if (ate !== undefined && ate !== current_editor) {
618617
// Send a new current file after a short delay; this allows
619618
// the user to rapidly cycle through several editors without
620619
// needing to reload the Client with each cycle.
@@ -644,12 +643,14 @@ const send_update = (this_is_dirty: boolean) => {
644643
// CodeMirror
645644
// [Text.line](https://codemirror.net/docs/ref/#state.Text.line)
646645
// is 1-based.
647-
const cursor_position = ate.selection.active.line + 1;
648-
const scroll_position = ate.visibleRanges[0].start.line + 1;
649-
const file_path = ate.document.fileName;
646+
const cursor_position =
647+
current_editor!.selection.active.line + 1;
648+
const scroll_position =
649+
current_editor!.visibleRanges[0].start.line + 1;
650+
const file_path = current_editor!.document.fileName;
650651
// Send contents only if necessary.
651652
const option_contents: null | [string, number] = is_dirty
652-
? [ate.document.getText(), (version = rand())]
653+
? [current_editor!.document.getText(), (version = rand())]
653654
: null;
654655
is_dirty = false;
655656
console_log(
@@ -714,8 +715,10 @@ const show_error = (message: string) => {
714715
// client, and the webview is visible.
715716
const can_render = () => {
716717
return (
717-
vscode.window.activeTextEditor !== undefined &&
718+
(vscode.window.activeTextEditor !== undefined ||
719+
current_editor !== undefined) &&
718720
codeChatEditorServer !== undefined &&
721+
// TODO: I don't think these matter -- the Server is in charge of sending output to the Client.
719722
(codechat_client_location === CodeChatEditorClientLocation.browser ||
720723
webview_panel !== undefined)
721724
);

0 commit comments

Comments
 (0)