cursor width on unicode char

This commit is contained in:
Dongdong Zhou 2021-09-16 17:03:04 +01:00
parent dc58beaeea
commit 956fc2689f
4 changed files with 23 additions and 4 deletions

2
Cargo.lock generated
View File

@ -3205,6 +3205,7 @@ dependencies = [
"font-kit",
"futures",
"glam",
"include_dir",
"linked-hash-map",
"lyon",
"pathfinder_geometry",
@ -3212,6 +3213,7 @@ dependencies = [
"raw-window-handle",
"rustc-hash",
"sha2 0.9.8",
"unicode-width",
"usvg",
"wgpu",
]

View File

@ -3040,4 +3040,4 @@ pub fn grapheme_column_width(s: &str) -> usize {
}
}
UnicodeWidthStr::width(s)
}
}

View File

@ -65,6 +65,7 @@
use std::{cmp::Ordering, iter::Iterator, path::PathBuf};
use std::{collections::HashMap, sync::Arc};
use std::{str::FromStr, time::Duration};
use unicode_width::UnicodeWidthStr;
use xi_core_lib::selection::InsertDrift;
use xi_rope::{Interval, RopeDelta};
@ -1193,13 +1194,23 @@ fn paint_cursor(
if active {
let cursor_x = col as f64 * width;
let next = data.buffer.next_grapheme_offset(
*offset,
1,
data.buffer.len(),
);
let char = data.buffer.slice_to_cow(*offset..next).to_string();
let char_width = UnicodeWidthStr::width(char.as_str()).max(1);
ctx.fill(
Rect::ZERO
.with_origin(Point::new(
cursor_x,
line as f64 * line_height,
))
.with_size(Size::new(width, line_height)),
.with_size(Size::new(
width * char_width as f64,
line_height,
)),
&env.get(LapceTheme::EDITOR_CURSOR_COLOR),
);
}
@ -1272,13 +1283,20 @@ fn paint_cursor(
let (line, col) = data.buffer.offset_to_line_col(*end);
let cursor_x = col as f64 * width;
let next =
data.buffer.next_grapheme_offset(*end, 1, data.buffer.len());
let char = data.buffer.slice_to_cow(*end..next).to_string();
let char_width = UnicodeWidthStr::width(char.as_str()).max(1);
ctx.fill(
Rect::ZERO
.with_origin(Point::new(
cursor_x,
line as f64 * line_height,
))
.with_size(Size::new(width, line_height)),
.with_size(Size::new(
width * char_width as f64,
line_height,
)),
&env.get(LapceTheme::EDITOR_CURSOR_COLOR),
);
}

View File

@ -294,7 +294,6 @@ pub fn start_update_process(
if let Some((diff, line_changes)) =
file_git_diff(&workspace, &PathBuf::from(path), &content)
{
eprintln!("diff {:?}", diff);
self.sender.send(json!({
"method": "update_git",
"params": {