resolve all lints, update MSRV
This commit is contained in:
parent
166b59f560
commit
f05a69a9d9
18 changed files with 251 additions and 283 deletions
|
|
@ -109,6 +109,7 @@ impl<'buffer> Editor<'buffer> {
|
|||
|
||||
/// Draw the editor
|
||||
#[cfg(feature = "swash")]
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn draw<F>(
|
||||
&self,
|
||||
font_system: &mut FontSystem,
|
||||
|
|
@ -527,16 +528,13 @@ impl<'buffer> Edit<'buffer> for Editor<'buffer> {
|
|||
|
||||
fn apply_change(&mut self, change: &Change) -> bool {
|
||||
// Cannot apply changes if there is a pending change
|
||||
match self.change.take() {
|
||||
Some(pending) => {
|
||||
if !pending.items.is_empty() {
|
||||
//TODO: is this a good idea?
|
||||
log::warn!("pending change caused apply_change to be ignored!");
|
||||
self.change = Some(pending);
|
||||
return false;
|
||||
}
|
||||
if let Some(pending) = self.change.take() {
|
||||
if !pending.items.is_empty() {
|
||||
//TODO: is this a good idea?
|
||||
log::warn!("pending change caused apply_change to be ignored!");
|
||||
self.change = Some(pending);
|
||||
return false;
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
|
||||
for item in change.items.iter() {
|
||||
|
|
@ -898,7 +896,7 @@ impl<'buffer> Edit<'buffer> for Editor<'buffer> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'font_system, 'buffer> BorrowedWithFontSystem<'font_system, Editor<'buffer>> {
|
||||
impl BorrowedWithFontSystem<'_, Editor<'_>> {
|
||||
#[cfg(feature = "swash")]
|
||||
pub fn draw<F>(
|
||||
&mut self,
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ pub enum BufferRef<'buffer> {
|
|||
Arc(Arc<Buffer>),
|
||||
}
|
||||
|
||||
impl<'buffer> Clone for BufferRef<'buffer> {
|
||||
impl Clone for BufferRef<'_> {
|
||||
fn clone(&self) -> Self {
|
||||
match self {
|
||||
Self::Owned(buffer) => Self::Owned(buffer.clone()),
|
||||
|
|
@ -81,7 +81,7 @@ impl<'buffer> Clone for BufferRef<'buffer> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'buffer> From<Buffer> for BufferRef<'buffer> {
|
||||
impl From<Buffer> for BufferRef<'_> {
|
||||
fn from(buffer: Buffer) -> Self {
|
||||
Self::Owned(buffer)
|
||||
}
|
||||
|
|
@ -93,7 +93,7 @@ impl<'buffer> From<&'buffer mut Buffer> for BufferRef<'buffer> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'buffer> From<Arc<Buffer>> for BufferRef<'buffer> {
|
||||
impl From<Arc<Buffer>> for BufferRef<'_> {
|
||||
fn from(arc: Arc<Buffer>) -> Self {
|
||||
Self::Arc(arc)
|
||||
}
|
||||
|
|
@ -197,7 +197,7 @@ pub trait Edit<'buffer> {
|
|||
|
||||
/// Set the [`Buffer`] redraw flag
|
||||
fn set_redraw(&mut self, redraw: bool) {
|
||||
self.with_buffer_mut(|buffer| buffer.set_redraw(redraw))
|
||||
self.with_buffer_mut(|buffer| buffer.set_redraw(redraw));
|
||||
}
|
||||
|
||||
/// Get the current cursor
|
||||
|
|
@ -300,7 +300,7 @@ pub trait Edit<'buffer> {
|
|||
/// Delete text starting at start Cursor and ending at end Cursor
|
||||
fn delete_range(&mut self, start: Cursor, end: Cursor);
|
||||
|
||||
/// Insert text at specified cursor with specified attrs_list
|
||||
/// Insert text at specified cursor with specified `attrs_list`
|
||||
fn insert_at(&mut self, cursor: Cursor, data: &str, attrs_list: Option<AttrsList>) -> Cursor;
|
||||
|
||||
/// Copy selection
|
||||
|
|
@ -334,7 +334,7 @@ pub trait Edit<'buffer> {
|
|||
fn cursor_position(&self) -> Option<(i32, i32)>;
|
||||
}
|
||||
|
||||
impl<'font_system, 'buffer, E: Edit<'buffer>> BorrowedWithFontSystem<'font_system, E> {
|
||||
impl<'buffer, E: Edit<'buffer>> BorrowedWithFontSystem<'_, E> {
|
||||
/// Get the internal [`Buffer`], mutably
|
||||
pub fn with_buffer_mut<F: FnOnce(&mut BorrowedWithFontSystem<Buffer>) -> T, T>(
|
||||
&mut self,
|
||||
|
|
|
|||
|
|
@ -125,7 +125,7 @@ impl<'syntax_system, 'buffer> SyntaxEditor<'syntax_system, 'buffer> {
|
|||
|
||||
let text = fs::read_to_string(path)?;
|
||||
self.editor.with_buffer_mut(|buffer| {
|
||||
buffer.set_text(font_system, &text, attrs, Shaping::Advanced)
|
||||
buffer.set_text(font_system, &text, attrs, Shaping::Advanced);
|
||||
});
|
||||
|
||||
//TODO: re-use text
|
||||
|
|
@ -235,7 +235,7 @@ impl<'syntax_system, 'buffer> SyntaxEditor<'syntax_system, 'buffer> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'syntax_system, 'buffer> Edit<'buffer> for SyntaxEditor<'syntax_system, 'buffer> {
|
||||
impl<'buffer> Edit<'buffer> for SyntaxEditor<'_, 'buffer> {
|
||||
fn buffer_ref(&self) -> &BufferRef<'buffer> {
|
||||
self.editor.buffer_ref()
|
||||
}
|
||||
|
|
@ -440,9 +440,7 @@ impl<'syntax_system, 'buffer> Edit<'buffer> for SyntaxEditor<'syntax_system, 'bu
|
|||
}
|
||||
}
|
||||
|
||||
impl<'font_system, 'syntax_system, 'buffer>
|
||||
BorrowedWithFontSystem<'font_system, SyntaxEditor<'syntax_system, 'buffer>>
|
||||
{
|
||||
impl BorrowedWithFontSystem<'_, SyntaxEditor<'_, '_>> {
|
||||
/// Load text from a file, and also set syntax to the best option
|
||||
///
|
||||
/// ## Errors
|
||||
|
|
|
|||
|
|
@ -209,6 +209,9 @@ impl<'syntax_system, 'buffer> ViEditor<'syntax_system, 'buffer> {
|
|||
}
|
||||
|
||||
/// Load text from a file, and also set syntax to the best option
|
||||
///
|
||||
/// ## Errors
|
||||
/// Returns an `io::Error` if reading the file fails
|
||||
#[cfg(feature = "std")]
|
||||
pub fn load_text<P: AsRef<std::path::Path>>(
|
||||
&mut self,
|
||||
|
|
@ -517,7 +520,7 @@ impl<'syntax_system, 'buffer> ViEditor<'syntax_system, 'buffer> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'syntax_system, 'buffer> Edit<'buffer> for ViEditor<'syntax_system, 'buffer> {
|
||||
impl<'buffer> Edit<'buffer> for ViEditor<'_, 'buffer> {
|
||||
fn buffer_ref(&self) -> &BufferRef<'buffer> {
|
||||
self.editor.buffer_ref()
|
||||
}
|
||||
|
|
@ -646,10 +649,7 @@ impl<'syntax_system, 'buffer> Edit<'buffer> for ViEditor<'syntax_system, 'buffer
|
|||
}
|
||||
};
|
||||
|
||||
let has_selection = match editor.selection() {
|
||||
Selection::None => false,
|
||||
_ => true,
|
||||
};
|
||||
let has_selection = !matches!(editor.selection(), Selection::None);
|
||||
|
||||
self.parser.parse(key, has_selection, |event| {
|
||||
log::debug!(" Event {:?}", event);
|
||||
|
|
@ -778,17 +778,14 @@ impl<'syntax_system, 'buffer> Edit<'buffer> for ViEditor<'syntax_system, 'buffer
|
|||
TextObject::DoubleQuotes => select_in(editor, '"', '"', include),
|
||||
TextObject::Parentheses => select_in(editor, '(', ')', include),
|
||||
TextObject::Search { forwards } => {
|
||||
match &self.search_opt {
|
||||
Some((value, _)) => {
|
||||
if search(editor, value, forwards) {
|
||||
let mut cursor = editor.cursor();
|
||||
editor.set_selection(Selection::Normal(cursor));
|
||||
//TODO: traverse lines if necessary
|
||||
cursor.index += value.len();
|
||||
editor.set_cursor(cursor);
|
||||
}
|
||||
if let Some((value, _)) = &self.search_opt {
|
||||
if search(editor, value, forwards) {
|
||||
let mut cursor = editor.cursor();
|
||||
editor.set_selection(Selection::Normal(cursor));
|
||||
//TODO: traverse lines if necessary
|
||||
cursor.index += value.len();
|
||||
editor.set_cursor(cursor);
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
TextObject::SingleQuotes => select_in(editor, '\'', '\'', include),
|
||||
|
|
@ -880,15 +877,11 @@ impl<'syntax_system, 'buffer> Edit<'buffer> for ViEditor<'syntax_system, 'buffer
|
|||
editor.with_buffer(|buffer| {
|
||||
let text = buffer.lines[cursor.line].text();
|
||||
if cursor.index < text.len() {
|
||||
match text[cursor.index..]
|
||||
if let Some((i, _)) = text[cursor.index..]
|
||||
.char_indices()
|
||||
.filter(|&(i, c)| i > 0 && c == find_c)
|
||||
.next()
|
||||
.find(|&(i, c)| i > 0 && c == find_c)
|
||||
{
|
||||
Some((i, _)) => {
|
||||
cursor.index += i;
|
||||
}
|
||||
None => {}
|
||||
cursor.index += i;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -986,15 +979,11 @@ impl<'syntax_system, 'buffer> Edit<'buffer> for ViEditor<'syntax_system, 'buffer
|
|||
editor.with_buffer(|buffer| {
|
||||
let text = buffer.lines[cursor.line].text();
|
||||
if cursor.index > 0 {
|
||||
match text[..cursor.index]
|
||||
if let Some((i, _)) = text[..cursor.index]
|
||||
.char_indices()
|
||||
.filter(|&(_, c)| c == find_c)
|
||||
.last()
|
||||
.rfind(|&(_, c)| c == find_c)
|
||||
{
|
||||
Some((i, _)) => {
|
||||
cursor.index = i;
|
||||
}
|
||||
None => {}
|
||||
cursor.index = i;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -1006,7 +995,7 @@ impl<'syntax_system, 'buffer> Edit<'buffer> for ViEditor<'syntax_system, 'buffer
|
|||
editor.with_buffer(|buffer| {
|
||||
let text = buffer.lines[cursor.line].text();
|
||||
if cursor.index > 0 {
|
||||
match text[..cursor.index]
|
||||
if let Some(i) = text[..cursor.index]
|
||||
.char_indices()
|
||||
.filter_map(|(i, c)| {
|
||||
if c == find_c {
|
||||
|
|
@ -1019,10 +1008,7 @@ impl<'syntax_system, 'buffer> Edit<'buffer> for ViEditor<'syntax_system, 'buffer
|
|||
})
|
||||
.last()
|
||||
{
|
||||
Some(i) => {
|
||||
cursor.index = i;
|
||||
}
|
||||
None => {}
|
||||
cursor.index = i;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -1132,16 +1118,12 @@ impl<'syntax_system, 'buffer> Edit<'buffer> for ViEditor<'syntax_system, 'buffer
|
|||
//TODO: is this efficient?
|
||||
let action_opt = editor.with_buffer(|buffer| {
|
||||
let mut layout_runs = buffer.layout_runs();
|
||||
if let Some(first) = layout_runs.next() {
|
||||
if let Some(last) = layout_runs.last() {
|
||||
Some(Action::Motion(Motion::GotoLine(
|
||||
(last.line_i + first.line_i) / 2,
|
||||
)))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
} else {
|
||||
None
|
||||
|
||||
match (layout_runs.next(), layout_runs.last()) {
|
||||
(Some(first), Some(last)) => Some(Action::Motion(
|
||||
Motion::GotoLine((last.line_i + first.line_i) / 2),
|
||||
)),
|
||||
_ => None,
|
||||
}
|
||||
});
|
||||
match action_opt {
|
||||
|
|
@ -1167,10 +1149,11 @@ impl<'syntax_system, 'buffer> Edit<'buffer> for ViEditor<'syntax_system, 'buffer
|
|||
}
|
||||
}
|
||||
|
||||
impl<'font_system, 'syntax_system, 'buffer>
|
||||
BorrowedWithFontSystem<'font_system, ViEditor<'syntax_system, 'buffer>>
|
||||
{
|
||||
impl BorrowedWithFontSystem<'_, ViEditor<'_, '_>> {
|
||||
/// Load text from a file, and also set syntax to the best option
|
||||
///
|
||||
/// ## Errors
|
||||
/// Returns an `io::Error` if reading the file fails
|
||||
#[cfg(feature = "std")]
|
||||
pub fn load_text<P: AsRef<std::path::Path>>(
|
||||
&mut self,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue