Fix inverted char boundary check causing invalid offsets (#47112)

The logic in `anchor_at_offset` and `to_offset` seems inverted when
checking character boundaries. `assert_char_boundary` returns `true`
when the offset IS valid, but the code was adjusting offsets when the
function returned `true` (valid) instead of `false` (invalid).

Release Notes:

- N/A
This commit is contained in:
Jordi Villar authored and GitHub committed 2026-01-19 09:08:45 +01:00
1 parent c0a0e8b236
commit 3f9910cfae
1 file changed
+2 -2
+2 -2
View File
@@ -2417,7 +2417,7 @@ impl BufferSnapshot {
{
Anchor::max_for_buffer(self.remote_id)
} else {
if self
if !self
.visible_text
.assert_char_boundary::<{ cfg!(debug_assertions) }>(offset)
{
@@ -3125,7 +3125,7 @@ impl ToOffset for Point {
impl ToOffset for usize {
#[track_caller]
fn to_offset(&self, snapshot: &BufferSnapshot) -> usize {
if snapshot
if !snapshot
.as_rope()
.assert_char_boundary::<{ cfg!(debug_assertions) }>(*self)
{