~hime/protochat

eb9a9fe22a260f21d95d3492238fce9eb7319f94 — drbawb 4 months ago e5f6683
(ui/buffer): fix panic when using home/end keys

Home needs to update the position of `end` to be consistent w/ the
currently rendered span length, otherwise subtractions involving the end
of the span will underflow.

End likewise needs to update not just the cursor position, but also the
start and end of the current span. Otherwise the cursor will be
inserting text into a span that is rendered off-screen.
1 files changed, 4 insertions(+), 0 deletions(-)

M linetest/src/shell/ui/buffer.rs
M linetest/src/shell/ui/buffer.rs => linetest/src/shell/ui/buffer.rs +4 -0
@@ 238,10 238,14 @@ impl InputBuffer {

    pub fn goto_head(&mut self) {
        self.pos = 0;
        self.start = 0;
        self.end = self.span_len();
    }

    pub fn goto_tail(&mut self) {
        self.pos = self.buffer.len();
        self.end = self.pos;
        self.start = self.pos - self.span_len();
    }

    pub fn take(&mut self) -> String {