multi_buffer: Typed MultiBufferOffset (#42707)
This PR introduces a new `MultiBufferOffset` new type wrapping size. The goal of this is to make it clear at the type level when we are interacting with offsets of a multi buffer versus offsets of a language / text buffer. This improves readability of things quite a bit by making it clear what kind of offsets one is working with while also reducing accidental bugs by using the wrong kin of offset for the wrong API. This PR also uncovered two minor bugs due to that. Does not yet introduce the MultiBufferPoint equivalent, that is for a follow up PR. Release Notes: - N/A *or* Added/Fixed/Improved ...
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use collections::VecDeque;
|
||||
use copilot::Copilot;
|
||||
use editor::{Editor, EditorEvent, actions::MoveToEnd, scroll::Autoscroll};
|
||||
use editor::{Editor, EditorEvent, MultiBufferOffset, actions::MoveToEnd, scroll::Autoscroll};
|
||||
use gpui::{
|
||||
AnyView, App, Context, Corner, Entity, EventEmitter, FocusHandle, Focusable, IntoElement,
|
||||
ParentElement, Render, Styled, Subscription, Task, WeakEntity, Window, actions, div,
|
||||
@@ -231,7 +231,7 @@ impl LspLogView {
|
||||
let last_offset = editor.buffer().read(cx).len(cx);
|
||||
let newest_cursor_is_at_end = editor
|
||||
.selections
|
||||
.newest::<usize>(&editor.display_snapshot(cx))
|
||||
.newest::<MultiBufferOffset>(&editor.display_snapshot(cx))
|
||||
.start
|
||||
>= last_offset;
|
||||
editor.edit(
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use command_palette_hooks::CommandPaletteFilter;
|
||||
use editor::{Anchor, Editor, ExcerptId, SelectionEffects, scroll::Autoscroll};
|
||||
use editor::{Anchor, Editor, ExcerptId, MultiBufferOffset, SelectionEffects, scroll::Autoscroll};
|
||||
use gpui::{
|
||||
App, AppContext as _, Context, Div, Entity, EntityId, EventEmitter, FocusHandle, Focusable,
|
||||
Hsla, InteractiveElement, IntoElement, MouseButton, MouseDownEvent, MouseMoveEvent,
|
||||
@@ -254,7 +254,7 @@ impl SyntaxTreeView {
|
||||
let (buffer, range, excerpt_id) = editor_state.editor.update(cx, |editor, cx| {
|
||||
let selection_range = editor
|
||||
.selections
|
||||
.last::<usize>(&editor.display_snapshot(cx))
|
||||
.last::<MultiBufferOffset>(&editor.display_snapshot(cx))
|
||||
.range();
|
||||
let multi_buffer = editor.buffer().read(cx);
|
||||
let (buffer, range, excerpt_id) = snapshot
|
||||
@@ -308,8 +308,8 @@ impl SyntaxTreeView {
|
||||
// Within the active layer, find the syntax node under the cursor,
|
||||
// and scroll to it.
|
||||
let mut cursor = layer.node().walk();
|
||||
while cursor.goto_first_child_for_byte(range.start).is_some() {
|
||||
if !range.is_empty() && cursor.node().end_byte() == range.start {
|
||||
while cursor.goto_first_child_for_byte(range.start.0).is_some() {
|
||||
if !range.is_empty() && cursor.node().end_byte() == range.start.0 {
|
||||
cursor.goto_next_sibling();
|
||||
}
|
||||
}
|
||||
@@ -317,7 +317,7 @@ impl SyntaxTreeView {
|
||||
// Ascend to the smallest ancestor that contains the range.
|
||||
loop {
|
||||
let node_range = cursor.node().byte_range();
|
||||
if node_range.start <= range.start && node_range.end >= range.end {
|
||||
if node_range.start <= range.start.0 && node_range.end >= range.end.0 {
|
||||
break;
|
||||
}
|
||||
if !cursor.goto_parent() {
|
||||
|
||||
Reference in New Issue
Block a user