fixing some claude-isms

Orual 3d475648 a4ea50c1

+121 -36
+19 -18
crates/weaver-app/src/components/editor/document.rs
··· 200 200 impl EditorDocument { 201 201 /// Check if a character position is within the block-syntax zone of its line. 202 202 fn is_in_block_syntax_zone(&self, pos: usize) -> bool { 203 - if pos == 0 { 203 + if pos <= BLOCK_SYNTAX_ZONE { 204 204 return true; 205 205 } 206 206 207 - let content_str = self.content.to_string(); 208 - let mut last_newline_pos: Option<usize> = None; 209 - 210 - for (i, c) in content_str.chars().take(pos).enumerate() { 211 - if c == '\n' { 212 - last_newline_pos = Some(i); 207 + // Search backwards from pos-1, only need to check BLOCK_SYNTAX_ZONE + 1 chars. 208 + let search_start = pos.saturating_sub(BLOCK_SYNTAX_ZONE + 1); 209 + for i in (search_start..pos).rev() { 210 + if self.content.char_at(i).ok() == Some('\n') { 211 + // Found newline at i, distance from line start is pos - i - 1. 212 + return (pos - i - 1) <= BLOCK_SYNTAX_ZONE; 213 213 } 214 214 } 215 - 216 - let chars_from_line_start = match last_newline_pos { 217 - Some(nl_pos) => pos - nl_pos - 1, 218 - None => pos, 219 - }; 220 - 221 - chars_from_line_start <= BLOCK_SYNTAX_ZONE 215 + // No newline found in search range, and pos > BLOCK_SYNTAX_ZONE, so not in zone. 216 + false 222 217 } 223 218 224 219 /// Create a new editor document with the given content. ··· 695 690 696 691 /// Remove text range from content and record edit info for incremental rendering. 697 692 pub fn remove_tracked(&mut self, start: usize, len: usize) -> LoroResult<()> { 698 - let content_str = self.content.to_string(); 699 - let contains_newline = content_str.chars().skip(start).take(len).any(|c| c == '\n'); 693 + let contains_newline = self 694 + .content 695 + .slice(start, start + len) 696 + .map(|s| s.contains('\n')) 697 + .unwrap_or(false); 700 698 let in_block_syntax_zone = self.is_in_block_syntax_zone(start); 701 699 702 700 let result = self.content.delete(start, len); ··· 714 712 715 713 /// Replace text in content (delete then insert) and record combined edit info. 716 714 pub fn replace_tracked(&mut self, start: usize, len: usize, text: &str) -> LoroResult<()> { 717 - let content_str = self.content.to_string(); 718 - let delete_has_newline = content_str.chars().skip(start).take(len).any(|c| c == '\n'); 715 + let delete_has_newline = self 716 + .content 717 + .slice(start, start + len) 718 + .map(|s| s.contains('\n')) 719 + .unwrap_or(false); 719 720 let in_block_syntax_zone = self.is_in_block_syntax_zone(start); 720 721 721 722 let len_before = self.content.len_unicode();
+14 -18
crates/weaver-editor-crdt/src/buffer.rs
··· 4 4 use std::ops::Range; 5 5 use std::rc::Rc; 6 6 7 - use loro::{LoroDoc, LoroText, UndoManager as LoroUndoManager, VersionVector}; 7 + use loro::{cursor::PosType, LoroDoc, LoroText, UndoManager as LoroUndoManager, VersionVector}; 8 8 use smol_str::{SmolStr, ToSmolStr}; 9 9 use weaver_editor_core::{TextBuffer, UndoManager}; 10 10 ··· 110 110 111 111 impl TextBuffer for LoroTextBuffer { 112 112 fn len_bytes(&self) -> usize { 113 - self.content.to_string().len() 113 + self.content.len_utf8() 114 114 } 115 115 116 116 fn len_chars(&self) -> usize { ··· 126 126 } 127 127 128 128 fn slice(&self, char_range: Range<usize>) -> Option<SmolStr> { 129 - let s = self.content.to_string(); 130 - let chars: Vec<char> = s.chars().collect(); 131 - 132 - if char_range.end > chars.len() { 129 + if char_range.end > self.content.len_unicode() { 133 130 return None; 134 131 } 135 - 136 - let slice: String = chars[char_range].iter().collect(); 137 - Some(slice.to_smolstr()) 132 + self.content 133 + .slice(char_range.start, char_range.end) 134 + .ok() 135 + .map(|s| s.to_smolstr()) 138 136 } 139 137 140 138 fn char_at(&self, char_offset: usize) -> Option<char> { 141 - let s = self.content.to_string(); 142 - s.chars().nth(char_offset) 139 + self.content.char_at(char_offset).ok() 143 140 } 144 141 145 142 fn to_string(&self) -> String { ··· 147 144 } 148 145 149 146 fn char_to_byte(&self, char_offset: usize) -> usize { 150 - let s = self.content.to_string(); 151 - s.char_indices() 152 - .nth(char_offset) 153 - .map(|(i, _)| i) 154 - .unwrap_or(s.len()) 147 + self.content 148 + .convert_pos(char_offset, PosType::Unicode, PosType::Bytes) 149 + .unwrap_or(self.content.len_utf8()) 155 150 } 156 151 157 152 fn byte_to_char(&self, byte_offset: usize) -> usize { 158 - let s = self.content.to_string(); 159 - s[..byte_offset.min(s.len())].chars().count() 153 + self.content 154 + .convert_pos(byte_offset, PosType::Bytes, PosType::Unicode) 155 + .unwrap_or(self.content.len_unicode()) 160 156 } 161 157 } 162 158
+88
docs/graph-data.json
··· 1704 1704 "created_at": "2026-01-06T14:36:23.710415853-05:00", 1705 1705 "updated_at": "2026-01-06T14:36:23.710415853-05:00", 1706 1706 "metadata_json": "{\"confidence\":95}" 1707 + }, 1708 + { 1709 + "id": 157, 1710 + "change_id": "e1666f70-0b8a-4a9e-9716-bd550899e65c", 1711 + "node_type": "action", 1712 + "title": "Moved fetch_blob to WeaverExt trait in weaver-common", 1713 + "description": null, 1714 + "status": "pending", 1715 + "created_at": "2026-01-06T15:16:33.868867777-05:00", 1716 + "updated_at": "2026-01-06T15:16:33.868867777-05:00", 1717 + "metadata_json": "{\"confidence\":95}" 1718 + }, 1719 + { 1720 + "id": 158, 1721 + "change_id": "89ef84b5-0909-4367-8644-4392c1cf4c3a", 1722 + "node_type": "action", 1723 + "title": "Added use-index cfg gates to crdt sync functions (find_all_edit_roots, list_drafts)", 1724 + "description": null, 1725 + "status": "pending", 1726 + "created_at": "2026-01-06T15:16:33.886464900-05:00", 1727 + "updated_at": "2026-01-06T15:16:33.886464900-05:00", 1728 + "metadata_json": "{\"confidence\":95}" 1729 + }, 1730 + { 1731 + "id": 159, 1732 + "change_id": "f3f310fb-78e3-4178-98a3-20d55e20c85a", 1733 + "node_type": "action", 1734 + "title": "Refactored app sync.rs - removed ~1100 lines of duplicated code, re-exports crdt types", 1735 + "description": null, 1736 + "status": "pending", 1737 + "created_at": "2026-01-06T15:16:33.904856197-05:00", 1738 + "updated_at": "2026-01-06T15:16:33.904856197-05:00", 1739 + "metadata_json": "{\"confidence\":95}" 1740 + }, 1741 + { 1742 + "id": 160, 1743 + "change_id": "da49b35a-6ca3-4d59-a1f8-84f359693565", 1744 + "node_type": "outcome", 1745 + "title": "Sync extraction complete - app sync.rs now thin wrapper over weaver-editor-crdt, both use-index and non-use-index paths compile", 1746 + "description": null, 1747 + "status": "pending", 1748 + "created_at": "2026-01-06T15:16:33.936978250-05:00", 1749 + "updated_at": "2026-01-06T15:16:33.936978250-05:00", 1750 + "metadata_json": "{\"confidence\":95}" 1707 1751 } 1708 1752 ], 1709 1753 "edges": [ ··· 3477 3521 "weight": 1.0, 3478 3522 "rationale": "Completed fix", 3479 3523 "created_at": "2026-01-06T14:36:23.726201054-05:00" 3524 + }, 3525 + { 3526 + "id": 163, 3527 + "from_node_id": 153, 3528 + "to_node_id": 157, 3529 + "from_change_id": "f357a30f-0000-4b09-bb35-fe6c23b1dccf", 3530 + "to_change_id": "e1666f70-0b8a-4a9e-9716-bd550899e65c", 3531 + "edge_type": "leads_to", 3532 + "weight": 1.0, 3533 + "rationale": "fetch_blob needed for crdt sync to work standalone", 3534 + "created_at": "2026-01-06T15:16:39.378273071-05:00" 3535 + }, 3536 + { 3537 + "id": 164, 3538 + "from_node_id": 157, 3539 + "to_node_id": 158, 3540 + "from_change_id": "e1666f70-0b8a-4a9e-9716-bd550899e65c", 3541 + "to_change_id": "89ef84b5-0909-4367-8644-4392c1cf4c3a", 3542 + "edge_type": "leads_to", 3543 + "weight": 1.0, 3544 + "rationale": "cfg gates next step after fetch_blob available", 3545 + "created_at": "2026-01-06T15:16:39.394339283-05:00" 3546 + }, 3547 + { 3548 + "id": 165, 3549 + "from_node_id": 158, 3550 + "to_node_id": 159, 3551 + "from_change_id": "89ef84b5-0909-4367-8644-4392c1cf4c3a", 3552 + "to_change_id": "f3f310fb-78e3-4178-98a3-20d55e20c85a", 3553 + "edge_type": "leads_to", 3554 + "weight": 1.0, 3555 + "rationale": "app sync.rs refactor follows crdt having both paths", 3556 + "created_at": "2026-01-06T15:16:39.410629272-05:00" 3557 + }, 3558 + { 3559 + "id": 166, 3560 + "from_node_id": 159, 3561 + "to_node_id": 160, 3562 + "from_change_id": "f3f310fb-78e3-4178-98a3-20d55e20c85a", 3563 + "to_change_id": "da49b35a-6ca3-4d59-a1f8-84f359693565", 3564 + "edge_type": "leads_to", 3565 + "weight": 1.0, 3566 + "rationale": "refactor completed successfully", 3567 + "created_at": "2026-01-06T15:16:39.426610084-05:00" 3480 3568 } 3481 3569 ] 3482 3570 }