Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix merge error #833

Merged
merged 2 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ use std::cmp::Ordering;

/// Height, width
pub type Unit = u16;

/// Character width / number of columns
pub(crate) fn cwidh(c: char) -> Unit {
use unicode_width::UnicodeWidthChar;
Unit::try_from(c.width().unwrap_or(0)).unwrap()
}
/// String width / number of columns
pub(crate) fn swidth(s: &str) -> Unit {
use unicode_width::UnicodeWidthStr;
Unit::try_from(s.width()).unwrap()
Expand Down
10 changes: 5 additions & 5 deletions src/line_buffer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Line buffer with current cursor position
use crate::keymap::{At, CharSearch, Movement, RepeatCount, Word};
use crate::layout::Layout;
use crate::layout::{swidth, Layout};
use std::cmp::min;
use std::fmt;
use std::iter;
Expand Down Expand Up @@ -588,7 +588,7 @@ impl LineBuffer {
pub fn move_to_line_up(&mut self, n: RepeatCount, layout: &Layout) -> bool {
match self.buf[..self.pos].rfind('\n') {
Some(off) => {
let column = self.buf[off + 1..self.pos].graphemes(true).count();
let column = swidth(&self.buf[off + 1..self.pos]);

let mut dest_start = self.buf[..off].rfind('\n').map_or(0, |n| n + 1);
let mut dest_end = off;
Expand All @@ -606,7 +606,7 @@ impl LineBuffer {
};
let gidx = self.buf[dest_start..dest_end]
.grapheme_indices(true)
.nth(column.saturating_sub(offset));
.nth(column.saturating_sub(offset) as usize);

self.pos = gidx.map_or(off, |(idx, _)| dest_start + idx); // if there's no enough columns
true
Expand Down Expand Up @@ -669,7 +669,7 @@ impl LineBuffer {
} else {
0
};
let column = self.buf[line_start..self.pos].graphemes(true).count() + offset;
let column = swidth(&self.buf[line_start..self.pos]) + offset;
let mut dest_start = self.pos + off + 1;
let mut dest_end = self.buf[dest_start..]
.find('\n')
Expand All @@ -685,7 +685,7 @@ impl LineBuffer {
}
self.pos = self.buf[dest_start..dest_end]
.grapheme_indices(true)
.nth(column)
.nth(column as usize)
.map_or(dest_end, |(idx, _)| dest_start + idx); // if there's no enough columns
debug_assert!(self.pos <= self.buf.len());
true
Expand Down
Loading