mirror of
https://github.com/crate-ci/typos.git
synced 2024-12-22 15:42:23 -05:00
fix: Fix misalignment in report highlight and indent
Previous method misaligns highlights when there are double width asian characters
```
39 | 한글 eglish
| ^^^^^^
```
This commit fixes the highlight to have correct alignment.
```
39 | 한글 eglish
| ^^^^^^
```
`unicode-rs` crate is used by the Rust compiler [1].
[1]: 34a6c9f26e/compiler/rustc_errors/src/emitter.rs (L861)
This commit is contained in:
parent
7d3e9bb070
commit
e096eb2095
3 changed files with 9 additions and 2 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -1576,6 +1576,7 @@ dependencies = [
|
|||
"typos-vars",
|
||||
"unicase",
|
||||
"unicode-segmentation",
|
||||
"unicode-width",
|
||||
"varcon-core",
|
||||
"yansi",
|
||||
]
|
||||
|
|
|
@ -91,6 +91,7 @@ encoding = "0.2"
|
|||
kstring = { version = "2.0.0", features = ["serde"] }
|
||||
typed-arena = "2.0.1"
|
||||
maplit = "1.0"
|
||||
unicode-width = "0.1.9"
|
||||
|
||||
[dev-dependencies]
|
||||
assert_fs = "1.0"
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
use std::io::{self, Write};
|
||||
use std::sync::atomic;
|
||||
|
||||
use unicode_width::UnicodeWidthStr;
|
||||
|
||||
use typos_cli::report::{Context, Message, Report, Typo};
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
|
@ -218,8 +220,11 @@ fn print_long_correction(msg: &Typo, palette: Palette) -> Result<(), std::io::Er
|
|||
let line_num = context.line_num.to_string();
|
||||
let line_indent: String = itertools::repeat_n(" ", line_num.len()).collect();
|
||||
|
||||
let hl_indent: String = itertools::repeat_n(" ", column).collect();
|
||||
let hl: String = itertools::repeat_n("^", msg.typo.len()).collect();
|
||||
let visible_column = UnicodeWidthStr::width(start.as_ref());
|
||||
let visible_len = UnicodeWidthStr::width(msg.typo);
|
||||
|
||||
let hl_indent: String = itertools::repeat_n(" ", visible_column).collect();
|
||||
let hl: String = itertools::repeat_n("^", visible_len).collect();
|
||||
|
||||
writeln!(handle, "{} |", line_indent)?;
|
||||
writeln!(
|
||||
|
|
Loading…
Reference in a new issue