Fix clippy lints
This commit is contained in:
parent
f4c51a96d5
commit
f14ef7a606
3 changed files with 41 additions and 22 deletions
|
|
@ -25,7 +25,7 @@ impl Editor {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn buffer(&self) -> &cosmic_text::Buffer {
|
pub fn buffer(&self) -> &cosmic_text::Buffer {
|
||||||
&self.internal().editor.buffer()
|
self.internal().editor.buffer()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn downgrade(&self) -> Weak {
|
pub fn downgrade(&self) -> Weak {
|
||||||
|
|
@ -53,11 +53,11 @@ impl editor::Editor for Editor {
|
||||||
line_height: 1.0,
|
line_height: 1.0,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let mut font_system =
|
||||||
|
text::font_system().write().expect("Write font system");
|
||||||
|
|
||||||
buffer.set_text(
|
buffer.set_text(
|
||||||
text::font_system()
|
font_system.raw(),
|
||||||
.write()
|
|
||||||
.expect("Write font system")
|
|
||||||
.raw(),
|
|
||||||
text,
|
text,
|
||||||
cosmic_text::Attrs::new(),
|
cosmic_text::Attrs::new(),
|
||||||
cosmic_text::Shaping::Advanced,
|
cosmic_text::Shaping::Advanced,
|
||||||
|
|
@ -65,6 +65,7 @@ impl editor::Editor for Editor {
|
||||||
|
|
||||||
Editor(Some(Arc::new(Internal {
|
Editor(Some(Arc::new(Internal {
|
||||||
editor: cosmic_text::Editor::new(buffer),
|
editor: cosmic_text::Editor::new(buffer),
|
||||||
|
version: font_system.version(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})))
|
})))
|
||||||
}
|
}
|
||||||
|
|
@ -347,6 +348,14 @@ impl editor::Editor for Editor {
|
||||||
|
|
||||||
let mut changed = false;
|
let mut changed = false;
|
||||||
|
|
||||||
|
if font_system.version() != internal.version {
|
||||||
|
for line in internal.editor.buffer_mut().lines.iter_mut() {
|
||||||
|
line.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
|
||||||
if new_font != internal.font {
|
if new_font != internal.font {
|
||||||
for line in internal.editor.buffer_mut().lines.iter_mut() {
|
for line in internal.editor.buffer_mut().lines.iter_mut() {
|
||||||
let _ = line.set_attrs_list(cosmic_text::AttrsList::new(
|
let _ = line.set_attrs_list(cosmic_text::AttrsList::new(
|
||||||
|
|
@ -383,7 +392,7 @@ impl editor::Editor for Editor {
|
||||||
}
|
}
|
||||||
|
|
||||||
if changed {
|
if changed {
|
||||||
internal.min_bounds = text::measure(&internal.editor.buffer());
|
internal.min_bounds = text::measure(internal.editor.buffer());
|
||||||
}
|
}
|
||||||
|
|
||||||
self.0 = Some(Arc::new(internal));
|
self.0 = Some(Arc::new(internal));
|
||||||
|
|
@ -453,11 +462,11 @@ impl PartialEq for Weak {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn highlight_line<'a>(
|
fn highlight_line(
|
||||||
line: &'a cosmic_text::BufferLine,
|
line: &cosmic_text::BufferLine,
|
||||||
from: usize,
|
from: usize,
|
||||||
to: usize,
|
to: usize,
|
||||||
) -> impl Iterator<Item = (f32, f32)> + 'a {
|
) -> impl Iterator<Item = (f32, f32)> + '_ {
|
||||||
let layout = line
|
let layout = line
|
||||||
.layout_opt()
|
.layout_opt()
|
||||||
.as_ref()
|
.as_ref()
|
||||||
|
|
|
||||||
|
|
@ -210,9 +210,9 @@ where
|
||||||
/// Creates a new [`TextEditor`].
|
/// Creates a new [`TextEditor`].
|
||||||
///
|
///
|
||||||
/// [`TextEditor`]: crate::TextEditor
|
/// [`TextEditor`]: crate::TextEditor
|
||||||
pub fn text_editor<'a, Message, Renderer>(
|
pub fn text_editor<Message, Renderer>(
|
||||||
content: &'a text_editor::Content<Renderer>,
|
content: &text_editor::Content<Renderer>,
|
||||||
) -> TextEditor<'a, Message, Renderer>
|
) -> TextEditor<'_, Message, Renderer>
|
||||||
where
|
where
|
||||||
Message: Clone,
|
Message: Clone,
|
||||||
Renderer: core::text::Renderer,
|
Renderer: core::text::Renderer,
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,8 @@ use crate::core::text::editor::{Cursor, Editor as _};
|
||||||
use crate::core::text::{self, LineHeight};
|
use crate::core::text::{self, LineHeight};
|
||||||
use crate::core::widget::{self, Widget};
|
use crate::core::widget::{self, Widget};
|
||||||
use crate::core::{
|
use crate::core::{
|
||||||
Clipboard, Color, Element, Length, Padding, Pixels, Point, Rectangle,
|
Clipboard, Color, Element, Length, Padding, Pixels, Rectangle, Shell,
|
||||||
Shell, Vector,
|
Vector,
|
||||||
};
|
};
|
||||||
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
|
|
@ -205,8 +205,12 @@ where
|
||||||
Update::Edit(action) => {
|
Update::Edit(action) => {
|
||||||
shell.publish(on_edit(action));
|
shell.publish(on_edit(action));
|
||||||
}
|
}
|
||||||
Update::Copy => {}
|
Update::Copy => todo!(),
|
||||||
Update::Paste => if let Some(_contents) = clipboard.read() {},
|
Update::Paste => {
|
||||||
|
if let Some(_contents) = clipboard.read() {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
event::Status::Captured
|
event::Status::Captured
|
||||||
|
|
@ -353,7 +357,6 @@ impl Update {
|
||||||
cursor: mouse::Cursor,
|
cursor: mouse::Cursor,
|
||||||
) -> Option<Self> {
|
) -> Option<Self> {
|
||||||
let edit = |action| Some(Update::Edit(action));
|
let edit = |action| Some(Update::Edit(action));
|
||||||
let move_ = |motion| Some(Update::Edit(Action::Move(motion)));
|
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
Event::Mouse(event) => match event {
|
Event::Mouse(event) => match event {
|
||||||
|
|
@ -399,11 +402,12 @@ impl Update {
|
||||||
modifiers,
|
modifiers,
|
||||||
} if state.is_focused => {
|
} if state.is_focused => {
|
||||||
if let Some(motion) = motion(key_code) {
|
if let Some(motion) = motion(key_code) {
|
||||||
let motion = if modifiers.control() {
|
let motion =
|
||||||
motion.widen()
|
if platform::is_jump_modifier_pressed(modifiers) {
|
||||||
} else {
|
motion.widen()
|
||||||
motion
|
} else {
|
||||||
};
|
motion
|
||||||
|
};
|
||||||
|
|
||||||
return edit(if modifiers.shift() {
|
return edit(if modifiers.shift() {
|
||||||
Action::Select(motion)
|
Action::Select(motion)
|
||||||
|
|
@ -417,6 +421,12 @@ impl Update {
|
||||||
keyboard::KeyCode::Backspace => edit(Action::Backspace),
|
keyboard::KeyCode::Backspace => edit(Action::Backspace),
|
||||||
keyboard::KeyCode::Delete => edit(Action::Delete),
|
keyboard::KeyCode::Delete => edit(Action::Delete),
|
||||||
keyboard::KeyCode::Escape => Some(Self::Unfocus),
|
keyboard::KeyCode::Escape => Some(Self::Unfocus),
|
||||||
|
keyboard::KeyCode::C => Some(Self::Copy),
|
||||||
|
keyboard::KeyCode::V
|
||||||
|
if modifiers.command() && !modifiers.alt() =>
|
||||||
|
{
|
||||||
|
Some(Self::Paste)
|
||||||
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue