Skip to content

Commit 9bec903

Browse files
committed
Docs: wrap, update.
1 parent c3a4542 commit 9bec903

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

docs/changelog.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Changelog
2222
* [Github master](https://github.com/bjones1/CodeChat_Editor):
2323
* Fix indexing in diffs for characters that use more than one UTF-16 code
2424
unit, such as 😄,👉🏿,👨‍👦, and 🇺🇳.
25+
* Fix data corruption with adjacent doc blocks.
2526
* v0.1.23, 2025-Jul-24
2627
* Correct diff errors in IDE with CRLF line endings.
2728
* Upgrade to newest release of MathJax, TinyMCE.
@@ -124,4 +125,5 @@ Changelog
124125
* Cross-platform fixes.
125126
* v0.1.0, 2024-Oct-16:
126127
* Initial release, with binaries for Windows only. Built with
127-
manually-patched CodeMirror per \[this
128+
manually-patched CodeMirror per [this
129+
issue](https://github.com/bjones1/CodeChat_Editor/issues/27).

server/src/processing.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,9 @@ fn byte_index_of(s: &str, utf_16_index: usize) -> usize {
413413
/// Translate from CodeMirror to CodeDocBlocks.
414414
fn code_mirror_to_code_doc_blocks(code_mirror: &CodeMirror) -> Vec<CodeDocBlock> {
415415
let doc_blocks = &code_mirror.doc_blocks;
416-
// Translate between UTF-16 code units (the `from` and `to` provided by CodeMirror) and byte indexes (which Rust uses). Keep track of the current byte index/UTF-16 index; we always move forward from that location.
416+
// Translate between UTF-16 code units (the `from` and `to` provided by
417+
// CodeMirror) and byte indexes (which Rust uses). Keep track of the current
418+
// byte index/UTF-16 index; we always move forward from that location.
417419
let mut byte_index: usize = 0;
418420
let mut utf16_index: usize = 0;
419421
let mut code_doc_block_arr: Vec<CodeDocBlock> = Vec::new();
@@ -1060,15 +1062,17 @@ pub fn diff_code_mirror_doc_blocks(
10601062
&mut change_specs,
10611063
);
10621064

1063-
// If two doc blocks immediately follow each other: `# foo\n # bar\n`, for example,
1064-
// and a line is inserted before both, then a problem occurs when applying the change:
1065-
// applying the change to the first block sets its `from` value to the `from` value
1066-
// for the second block. This violates a doc blocks invariant -- each doc block
1067-
// must have a unique `from` value; therefore, these two doc blocks can no longer be
1068-
// distinguished, making it impossible to apply the change to the second doc block.
1069-
// More generally, this can occur with an insert before a series of blocks which
1070-
// immediately follow each other. Therefore, look for sequences of updates where `from_new` of a previous entry == `from` of the current
1071-
// entry and swap these sequences.
1065+
// If two doc blocks immediately follow each other: `# foo\n # bar\n`, for
1066+
// example, and a line is inserted before both, then a problem occurs when
1067+
// applying the change: applying the change to the first block sets its
1068+
// `from` value to the `from` value for the second block. This violates a
1069+
// doc blocks invariant -- each doc block must have a unique `from` value;
1070+
// therefore, these two doc blocks can no longer be distinguished, making it
1071+
// impossible to apply the change to the second doc block. More generally,
1072+
// this can occur with an insert before a series of blocks which immediately
1073+
// follow each other. Therefore, look for sequences of updates where
1074+
// `from_new` of a previous entry == `from` of the current entry and swap
1075+
// these sequences.
10721076
let mut immediate_sequence_start_index: Option<usize> = None;
10731077
for index in 1..change_specs.len() {
10741078
if let CodeMirrorDocBlockTransaction::Update(prev_update) = &change_specs[index - 1]

server/src/processing/tests.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,8 @@ fn test_diff_2() {
11221122
assert_eq!(
11231123
ret,
11241124
vec![
1125-
// Order is important -- first, 12->13, then 11->12, 10->11 (reversed order).
1125+
// Order is important -- first, 12->13, then 11->12, 10->11
1126+
// (reversed order).
11261127
CodeMirrorDocBlockTransaction::Update(CodeMirrorDocBlockUpdate {
11271128
from: 12,
11281129
from_new: 13,
@@ -1165,7 +1166,8 @@ fn test_diff_2() {
11651166
assert_eq!(
11661167
ret,
11671168
vec![
1168-
// Order is important -- 11->12, then 10->11 (reversed), then 13->14.
1169+
// Order is important -- 11->12, then 10->11 (reversed), then
1170+
// 13->14.
11691171
CodeMirrorDocBlockTransaction::Update(CodeMirrorDocBlockUpdate {
11701172
from: 11,
11711173
from_new: 12,

0 commit comments

Comments
 (0)