Skip to content

Commit

Permalink
Fix merge error
Browse files Browse the repository at this point in the history
  • Loading branch information
gwenn committed Dec 14, 2024
1 parent b4814bd commit cbced2a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::hint::Hint;
use crate::history::SearchDirection;
use crate::keymap::{Anchor, At, CharSearch, Cmd, Movement, RepeatCount, Word};
use crate::keymap::{InputState, Invoke, Refresher};
use crate::layout::{cwidh, Layout, Position};
use crate::layout::{cwidh, gcount, Layout, Position};

Check failure on line 14 in src/edit.rs

View workflow job for this annotation

GitHub Actions / Test min versions

unresolved import `crate::layout::gcount`
use crate::line_buffer::{
ChangeListener, DeleteListener, Direction, LineBuffer, NoListener, WordAction, MAX_LINE,
};
Expand Down
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

0 comments on commit cbced2a

Please sign in to comment.