Skip to content

Commit 2eef359

Browse files
committed
Add: Allow discarding re-translations.
Fix save logic.
1 parent bf59a39 commit 2eef359

File tree

12 files changed

+337
-206
lines changed

12 files changed

+337
-206
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Changelog
2222
[Github master](https://github.com/bjones1/CodeChat_Editor)
2323
--------------------------------------------------------------------------------
2424

25-
* Correctly re-translate Markdown documents.
25+
* Re-translate Markdown documents as necessary.
2626

2727
Version 0.1.47 -- 2025-Dec-19
2828
--------------------------------------------------------------------------------

client/src/CodeChatEditor.mts

Lines changed: 169 additions & 108 deletions
Large diffs are not rendered by default.

client/src/CodeChatEditorFramework.mts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -167,21 +167,27 @@ class WebSocketComm {
167167
if (contents !== undefined) {
168168
// Check and update the version. If this is a diff,
169169
// ensure the diff was made against the version of
170-
// the file we have.
170+
// the file we have. Ignore re-translation version errors, instead ignoring the update.
171171
if ("Diff" in contents.source) {
172172
if (
173173
contents.source.Diff.version !==
174174
this.version
175175
) {
176-
report_error(
177-
`Out of sync: Client version ${this.version} !== incoming version ${contents.source.Diff.version}.`,
178-
);
179-
this.send_result(id, {
180-
OutOfSync: [
181-
this.version,
182-
contents.source.Diff.version,
183-
],
184-
});
176+
if (current_update.is_re_translation) {
177+
console_log(
178+
`Ignoring out-of-sync re-translation update.`,
179+
);
180+
} else {
181+
report_error(
182+
`Out of sync: Client version ${this.version} !== incoming version ${contents.source.Diff.version}.`,
183+
);
184+
this.send_result(id, {
185+
OutOfSync: [
186+
this.version,
187+
contents.source.Diff.version,
188+
],
189+
});
190+
}
185191
return;
186192
}
187193
}
@@ -199,6 +205,7 @@ class WebSocketComm {
199205
// `on_dom_content_loaded` in the Client.
200206
await set_content(
201207
contents,
208+
current_update.is_re_translation,
202209
current_update.cursor_position,
203210
);
204211
} else {
@@ -214,6 +221,7 @@ class WebSocketComm {
214221
this.is_loading = false;
215222
await set_content(
216223
contents,
224+
current_update.is_re_translation,
217225
current_update.cursor_position,
218226
current_update.scroll_position,
219227
);
@@ -418,6 +426,7 @@ const get_client = () => root_iframe?.contentWindow?.CodeChatEditor;
418426
// in the `root_iframe`.
419427
const set_content = async (
420428
contents: CodeChatForWeb,
429+
is_re_translation: boolean,
421430
cursor_line?: number,
422431
scroll_line?: number,
423432
) => {
@@ -438,6 +447,7 @@ const set_content = async (
438447
} else {
439448
await root_iframe!.contentWindow!.CodeChatEditor.open_lp(
440449
contents,
450+
is_re_translation,
441451
cursor_line,
442452
scroll_line,
443453
);

client/src/tinymce-config.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,5 +174,5 @@ export const init = async (
174174
// Use these combined options to
175175
// [init](https://www.tiny.cloud/docs/tinymce/6/apis/tinymce.root/#init)
176176
// TinyMCE.
177-
return tinymce.init(combinedOptions);
177+
return await tinymce.init(combinedOptions);
178178
};

server/src/ide.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,9 @@ impl CodeChatEditorServer {
257257
) -> std::io::Result<f64> {
258258
self.send_message_timeout(EditorMessageContents::Update(UpdateMessageContents {
259259
file_path,
260+
cursor_position,
261+
scroll_position: scroll_position.map(|x| x as f32),
262+
is_re_translation: false,
260263
contents: option_contents.map(|contents| CodeChatForWeb {
261264
metadata: SourceFileMetadata {
262265
mode: "".to_string(),
@@ -267,8 +270,6 @@ impl CodeChatEditorServer {
267270
}),
268271
version: contents.1,
269272
}),
270-
cursor_position,
271-
scroll_position: scroll_position.map(|x| x as f32),
272273
}))
273274
.await
274275
}

server/src/ide/filewatcher.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,9 @@ async fn processing_task(
527527
id,
528528
message: EditorMessageContents::Update(UpdateMessageContents {
529529
file_path: current_filepath_str.to_string(),
530+
cursor_position: None,
531+
scroll_position: None,
532+
is_re_translation: false,
530533
contents: Some(CodeChatForWeb {
531534
metadata: SourceFileMetadata {
532535
// The IDE doesn't need to provide this.
@@ -544,8 +547,6 @@ async fn processing_task(
544547
// difference with fractional values.
545548
version: random::<u64>() as f64,
546549
}),
547-
cursor_position: None,
548-
scroll_position: None,
549550
}),
550551
}));
551552
id += MESSAGE_ID_INCREMENT;
@@ -927,9 +928,10 @@ mod tests {
927928
id: INITIAL_CLIENT_MESSAGE_ID,
928929
message: EditorMessageContents::Update(UpdateMessageContents {
929930
file_path: file_path.clone(),
930-
contents: None,
931931
cursor_position: None,
932932
scroll_position: None,
933+
is_re_translation: false,
934+
contents: None,
933935
}),
934936
})
935937
.await
@@ -975,6 +977,9 @@ mod tests {
975977
id: INITIAL_CLIENT_MESSAGE_ID + 4.0 * MESSAGE_ID_INCREMENT,
976978
message: EditorMessageContents::Update(UpdateMessageContents {
977979
file_path: "".to_string(),
980+
cursor_position: None,
981+
scroll_position: None,
982+
is_re_translation: false,
978983
contents: Some(CodeChatForWeb {
979984
metadata: SourceFileMetadata {
980985
mode: "".to_string(),
@@ -985,8 +990,6 @@ mod tests {
985990
}),
986991
version: 0.0,
987992
}),
988-
cursor_position: None,
989-
scroll_position: None,
990993
}),
991994
})
992995
.await
@@ -1010,6 +1013,9 @@ mod tests {
10101013
id: INITIAL_CLIENT_MESSAGE_ID + 5.0 * MESSAGE_ID_INCREMENT,
10111014
message: EditorMessageContents::Update(UpdateMessageContents {
10121015
file_path: file_path.clone(),
1016+
cursor_position: None,
1017+
scroll_position: None,
1018+
is_re_translation: false,
10131019
contents: Some(CodeChatForWeb {
10141020
metadata: SourceFileMetadata {
10151021
mode: "nope".to_string(),
@@ -1020,8 +1026,6 @@ mod tests {
10201026
}),
10211027
version: 1.0,
10221028
}),
1023-
cursor_position: None,
1024-
scroll_position: None,
10251029
}),
10261030
})
10271031
.await
@@ -1046,6 +1050,9 @@ mod tests {
10461050
id: INITIAL_CLIENT_MESSAGE_ID + 6.0 * MESSAGE_ID_INCREMENT,
10471051
message: EditorMessageContents::Update(UpdateMessageContents {
10481052
file_path: file_path.clone(),
1053+
cursor_position: None,
1054+
scroll_position: None,
1055+
is_re_translation: false,
10491056
contents: Some(CodeChatForWeb {
10501057
metadata: SourceFileMetadata {
10511058
mode: "python".to_string(),
@@ -1056,8 +1063,6 @@ mod tests {
10561063
}),
10571064
version: 2.0,
10581065
}),
1059-
cursor_position: None,
1060-
scroll_position: None,
10611066
}),
10621067
})
10631068
.await
@@ -1097,6 +1102,9 @@ mod tests {
10971102
INITIAL_IDE_MESSAGE_ID + MESSAGE_ID_INCREMENT,
10981103
UpdateMessageContents {
10991104
file_path: file_path.clone(),
1105+
cursor_position: None,
1106+
scroll_position: None,
1107+
is_re_translation: false,
11001108
contents: Some(CodeChatForWeb {
11011109
metadata: SourceFileMetadata {
11021110
mode: "python".to_string(),
@@ -1107,8 +1115,6 @@ mod tests {
11071115
}),
11081116
version: msg.1.contents.as_ref().unwrap().version,
11091117
}),
1110-
cursor_position: None,
1111-
scroll_position: None,
11121118
}
11131119
)
11141120
);

server/src/ide/vscode/tests.rs

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,10 @@ async fn test_vscode_ide_websocket1() {
262262
id: INITIAL_IDE_MESSAGE_ID,
263263
message: EditorMessageContents::Update(UpdateMessageContents {
264264
file_path: "".to_string(),
265-
contents: None,
266265
cursor_position: None,
267266
scroll_position: None,
267+
is_re_translation: false,
268+
contents: None,
268269
}),
269270
},
270271
)
@@ -542,6 +543,9 @@ async fn test_vscode_ide_websocket8() {
542543
id: INITIAL_MESSAGE_ID + 2.0 * MESSAGE_ID_INCREMENT,
543544
message: EditorMessageContents::Update(UpdateMessageContents {
544545
file_path: file_path_str.clone(),
546+
cursor_position: None,
547+
scroll_position: None,
548+
is_re_translation: false,
545549
contents: Some(CodeChatForWeb {
546550
metadata: SourceFileMetadata {
547551
mode: "python".to_string(),
@@ -558,8 +562,6 @@ async fn test_vscode_ide_websocket8() {
558562
}),
559563
version: 0.0,
560564
}),
561-
cursor_position: None,
562-
scroll_position: None,
563565
})
564566
}
565567
);
@@ -650,6 +652,9 @@ async fn test_vscode_ide_websocket7() {
650652
id: INITIAL_IDE_MESSAGE_ID,
651653
message: EditorMessageContents::Update(UpdateMessageContents {
652654
file_path: file_path_str.clone(),
655+
cursor_position: None,
656+
scroll_position: None,
657+
is_re_translation: false,
653658
contents: Some(CodeChatForWeb {
654659
metadata: SourceFileMetadata {
655660
mode: "python".to_string(),
@@ -660,8 +665,6 @@ async fn test_vscode_ide_websocket7() {
660665
}),
661666
version: 0.0,
662667
}),
663-
cursor_position: None,
664-
scroll_position: None,
665668
}),
666669
},
667670
)
@@ -672,6 +675,9 @@ async fn test_vscode_ide_websocket7() {
672675
id: INITIAL_IDE_MESSAGE_ID,
673676
message: EditorMessageContents::Update(UpdateMessageContents {
674677
file_path: file_path_str.clone(),
678+
cursor_position: None,
679+
scroll_position: None,
680+
is_re_translation: false,
675681
contents: Some(CodeChatForWeb {
676682
metadata: SourceFileMetadata {
677683
mode: "python".to_string(),
@@ -688,8 +694,6 @@ async fn test_vscode_ide_websocket7() {
688694
}),
689695
version: 0.0,
690696
}),
691-
cursor_position: None,
692-
scroll_position: None,
693697
})
694698
}
695699
);
@@ -718,6 +722,9 @@ async fn test_vscode_ide_websocket7() {
718722
id: INITIAL_IDE_MESSAGE_ID + 2.0 * MESSAGE_ID_INCREMENT,
719723
message: EditorMessageContents::Update(UpdateMessageContents {
720724
file_path: file_path_str.clone(),
725+
cursor_position: None,
726+
scroll_position: None,
727+
is_re_translation: false,
721728
contents: Some(CodeChatForWeb {
722729
metadata: SourceFileMetadata {
723730
mode: "python".to_string(),
@@ -734,8 +741,6 @@ async fn test_vscode_ide_websocket7() {
734741
}),
735742
version: 1.0,
736743
}),
737-
cursor_position: None,
738-
scroll_position: None,
739744
}),
740745
},
741746
)
@@ -746,6 +751,9 @@ async fn test_vscode_ide_websocket7() {
746751
id: INITIAL_IDE_MESSAGE_ID + 2.0 * MESSAGE_ID_INCREMENT,
747752
message: EditorMessageContents::Update(UpdateMessageContents {
748753
file_path: file_path_str.clone(),
754+
cursor_position: None,
755+
scroll_position: None,
756+
is_re_translation: false,
749757
contents: Some(CodeChatForWeb {
750758
metadata: SourceFileMetadata {
751759
mode: "python".to_string(),
@@ -767,8 +775,6 @@ async fn test_vscode_ide_websocket7() {
767775
}),
768776
version: 1.0,
769777
}),
770-
cursor_position: None,
771-
scroll_position: None,
772778
})
773779
}
774780
);
@@ -808,6 +814,9 @@ async fn test_vscode_ide_websocket6() {
808814
id: INITIAL_CLIENT_MESSAGE_ID,
809815
message: EditorMessageContents::Update(UpdateMessageContents {
810816
file_path: file_path.clone(),
817+
cursor_position: None,
818+
scroll_position: None,
819+
is_re_translation: false,
811820
contents: Some(CodeChatForWeb {
812821
metadata: SourceFileMetadata {
813822
mode: "python".to_string(),
@@ -824,8 +833,6 @@ async fn test_vscode_ide_websocket6() {
824833
}),
825834
version: 0.0,
826835
}),
827-
cursor_position: None,
828-
scroll_position: None,
829836
}),
830837
},
831838
)
@@ -836,6 +843,9 @@ async fn test_vscode_ide_websocket6() {
836843
id: INITIAL_CLIENT_MESSAGE_ID,
837844
message: EditorMessageContents::Update(UpdateMessageContents {
838845
file_path,
846+
cursor_position: None,
847+
scroll_position: None,
848+
is_re_translation: false,
839849
contents: Some(CodeChatForWeb {
840850
metadata: SourceFileMetadata {
841851
mode: "python".to_string(),
@@ -846,8 +856,6 @@ async fn test_vscode_ide_websocket6() {
846856
}),
847857
version: 0.0,
848858
}),
849-
cursor_position: None,
850-
scroll_position: None,
851859
})
852860
}
853861
);
@@ -973,6 +981,9 @@ async fn test_vscode_ide_websocket4() {
973981
id: INITIAL_MESSAGE_ID + 2.0 * MESSAGE_ID_INCREMENT,
974982
message: EditorMessageContents::Update(UpdateMessageContents {
975983
file_path: file_path_str.clone(),
984+
cursor_position: None,
985+
scroll_position: None,
986+
is_re_translation: false,
976987
contents: Some(CodeChatForWeb {
977988
metadata: SourceFileMetadata {
978989
mode: "python".to_string(),
@@ -993,8 +1004,6 @@ async fn test_vscode_ide_websocket4() {
9931004
.unwrap()
9941005
.version,
9951006
}),
996-
cursor_position: None,
997-
scroll_position: None,
9981007
})
9991008
}
10001009
);

0 commit comments

Comments
 (0)