mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-29 06:13:20 +00:00
Adopt count_newlines in additional places
This commit is contained in:
parent
4ea222cd34
commit
9bd4b3f878
1 changed files with 3 additions and 7 deletions
|
@ -26,6 +26,7 @@ use crate::tokenizer::{
|
||||||
TOK_SHOW_COMMENTS,
|
TOK_SHOW_COMMENTS,
|
||||||
};
|
};
|
||||||
use crate::wchar::prelude::*;
|
use crate::wchar::prelude::*;
|
||||||
|
use crate::wcstringutil::count_newlines;
|
||||||
use crate::wcstringutil::truncate;
|
use crate::wcstringutil::truncate;
|
||||||
use crate::wildcard::{ANY_CHAR, ANY_STRING, ANY_STRING_RECURSIVE};
|
use crate::wildcard::{ANY_CHAR, ANY_STRING, ANY_STRING_RECURSIVE};
|
||||||
use std::ops;
|
use std::ops;
|
||||||
|
@ -498,7 +499,7 @@ pub fn parse_util_lineno(s: &wstr, offset: usize) -> usize {
|
||||||
}
|
}
|
||||||
|
|
||||||
let end = offset.min(s.len());
|
let end = offset.min(s.len());
|
||||||
s.chars().take(end).filter(|c| *c == '\n').count() + 1
|
count_newlines(&s[..end]) + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Calculate the line number of the specified cursor position.
|
/// Calculate the line number of the specified cursor position.
|
||||||
|
@ -507,12 +508,7 @@ pub fn parse_util_get_line_from_offset(s: &wstr, pos: usize) -> isize {
|
||||||
if pos > s.len() {
|
if pos > s.len() {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
s.chars()
|
count_newlines(&s[..pos]).try_into().unwrap()
|
||||||
.take(pos)
|
|
||||||
.filter(|c| *c == '\n')
|
|
||||||
.count()
|
|
||||||
.try_into()
|
|
||||||
.unwrap()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the offset of the first character on the specified line.
|
/// Get the offset of the first character on the specified line.
|
||||||
|
|
Loading…
Reference in a new issue