From fc8758c6193f9f81e5f0279c53ee09c139ce8873 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Thu, 27 May 2021 09:37:17 -0700 Subject: [PATCH] Reset QueryCursors before putting them back in the pool Co-Authored-By: Antonio Scandurra --- zed/src/editor/buffer/mod.rs | 6 ++++-- zed/src/editor/buffer/point.rs | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/zed/src/editor/buffer/mod.rs b/zed/src/editor/buffer/mod.rs index 82fe359689..826e9b07eb 100644 --- a/zed/src/editor/buffer/mod.rs +++ b/zed/src/editor/buffer/mod.rs @@ -689,7 +689,7 @@ impl Buffer { (indent, is_whitespace) } - fn autoindent_for_rows(&self, rows: Range) -> Vec { + pub fn autoindent_for_rows(&self, rows: Range) -> Vec { // Find the indentation level of the previous non-whitespace row. let mut prev_row = rows.start; let prev_indent = loop { @@ -2237,7 +2237,9 @@ fn acquire_query_cursor() -> QueryCursor { .unwrap_or_else(|| QueryCursor::new()) } -fn release_query_cursor(cursor: QueryCursor) { +fn release_query_cursor(mut cursor: QueryCursor) { + cursor.set_byte_range(0, usize::MAX); + cursor.set_point_range(Point::zero().into(), Point::MAX.into()); QUERY_CURSORS.lock().push(cursor) } diff --git a/zed/src/editor/buffer/point.rs b/zed/src/editor/buffer/point.rs index f1fb81ef10..63deb052f6 100644 --- a/zed/src/editor/buffer/point.rs +++ b/zed/src/editor/buffer/point.rs @@ -10,6 +10,11 @@ pub struct Point { } impl Point { + pub const MAX: Self = Self { + row: u32::MAX, + column: u32::MAX, + }; + pub fn new(row: u32, column: u32) -> Self { Point { row, column } }