Skip to content

Commit 5de8912

Browse files
committed
improv: use text editor for notes
1 parent 53a9026 commit 5de8912

File tree

3 files changed

+71
-10
lines changed

3 files changed

+71
-10
lines changed

src/app.rs

+2
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,8 @@ impl Application for Tasks {
410410
self.details.subtasks.clear();
411411
self.details.sub_task_input_ids.clear();
412412
self.details.task = Some(task.clone());
413+
self.details.text_editor_content =
414+
widget::text_editor::Content::with_text(&task.notes);
413415
task.sub_tasks.into_iter().for_each(|task| {
414416
let id = self.details.subtasks.insert(task);
415417
self.details

src/app/key_bind.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub fn key_binds() -> HashMap<KeyBind, Action> {
2323

2424
bind!([Ctrl], Key::Character("n".into()), NewList);
2525
bind!([], Key::Named(Named::Delete), DeleteList);
26-
bind!([], Key::Named(Named::Enter), RenameList);
26+
bind!([Ctrl], Key::Character("r".into()), RenameList);
2727
bind!([Shift], Key::Character("I".into()), Icon);
2828
bind!([Ctrl], Key::Character("w".into()), WindowClose);
2929
bind!([Ctrl, Shift], Key::Character("n".into()), WindowNew);

src/details.rs

+68-9
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use crate::app::icon_cache::IconCache;
22
use chrono::{NaiveDate, TimeZone, Utc};
33
use cosmic::iced::{Alignment, Length};
44
use cosmic::iced_widget::row;
5-
use cosmic::widget::segmented_button;
65
use cosmic::widget::segmented_button::Entity;
6+
use cosmic::widget::{segmented_button, text_editor};
77
use cosmic::{theme, widget, Element};
88
use slotmap::{DefaultKey, SecondaryMap, SlotMap};
99
use tasks_core::models::{self, Priority, Status};
@@ -17,12 +17,13 @@ pub struct Details {
1717
pub subtasks: SlotMap<DefaultKey, models::Task>,
1818
pub editing: SecondaryMap<DefaultKey, bool>,
1919
pub sub_task_input_ids: SecondaryMap<DefaultKey, widget::Id>,
20+
pub text_editor_content: widget::text_editor::Content,
2021
}
2122

2223
#[derive(Debug, Clone)]
2324
pub enum Message {
2425
SetTitle(String),
25-
SetNotes(String),
26+
Editor(text_editor::Action),
2627
Favorite(bool),
2728
CompleteSubTask(DefaultKey, bool),
2829
DeleteSubTask(DefaultKey),
@@ -70,20 +71,22 @@ impl Details {
7071
subtasks: SlotMap::new(),
7172
editing: SecondaryMap::new(),
7273
sub_task_input_ids: SecondaryMap::new(),
74+
text_editor_content: widget::text_editor::Content::new(),
7375
}
7476
}
7577

7678
pub fn update(&mut self, message: Message) -> Vec<Task> {
7779
let mut tasks = vec![];
7880
match message {
79-
Message::SetTitle(title) => {
80-
if let Some(ref mut task) = &mut self.task {
81-
task.title.clone_from(&title);
81+
Message::Editor(action) => {
82+
if let Some(task) = &mut self.task {
83+
self.text_editor_content.perform(action);
84+
task.notes.clone_from(&self.text_editor_content.text());
8285
}
8386
}
84-
Message::SetNotes(notes) => {
87+
Message::SetTitle(title) => {
8588
if let Some(ref mut task) = &mut self.task {
86-
task.notes.clone_from(&notes);
89+
task.title.clone_from(&title);
8790
}
8891
}
8992
Message::Favorite(favorite) => {
@@ -251,8 +254,14 @@ impl Details {
251254
.add(
252255
widget::column::with_children(vec![
253256
widget::text::body(fl!("notes")).into(),
254-
widget::text_input(fl!("notes"), &task.notes)
255-
.on_input(Message::SetNotes)
257+
widget::text_editor(&self.text_editor_content)
258+
.class(cosmic::theme::iced::TextEditor::Custom(Box::new(
259+
text_editor_class,
260+
)))
261+
.padding(spacing.space_xxs)
262+
.placeholder(fl!("notes"))
263+
.height(100.0)
264+
.on_action(Message::Editor)
256265
.into(),
257266
])
258267
.spacing(spacing.space_xxs)
@@ -293,3 +302,53 @@ impl Details {
293302
.into()
294303
}
295304
}
305+
306+
fn text_editor_class(
307+
theme: &cosmic::Theme,
308+
status: cosmic::widget::text_editor::Status,
309+
) -> cosmic::iced_widget::text_editor::Style {
310+
let cosmic = theme.cosmic();
311+
let container = theme.current_container();
312+
313+
let mut background: cosmic::iced::Color = container.component.base.into();
314+
background.a = 0.25;
315+
let selection = cosmic.accent.base.into();
316+
let value = cosmic.palette.neutral_9.into();
317+
let mut placeholder = cosmic.palette.neutral_9;
318+
placeholder.alpha = 0.7;
319+
let placeholder = placeholder.into();
320+
let icon = cosmic.background.on.into();
321+
322+
match status {
323+
cosmic::iced_widget::text_editor::Status::Active
324+
| cosmic::iced_widget::text_editor::Status::Disabled => {
325+
cosmic::iced_widget::text_editor::Style {
326+
background: background.into(),
327+
border: cosmic::iced::Border {
328+
radius: cosmic.corner_radii.radius_m.into(),
329+
width: 2.0,
330+
color: container.component.divider.into(),
331+
},
332+
icon,
333+
placeholder,
334+
value,
335+
selection,
336+
}
337+
}
338+
cosmic::iced_widget::text_editor::Status::Hovered
339+
| cosmic::iced_widget::text_editor::Status::Focused => {
340+
cosmic::iced_widget::text_editor::Style {
341+
background: background.into(),
342+
border: cosmic::iced::Border {
343+
radius: cosmic.corner_radii.radius_m.into(),
344+
width: 2.0,
345+
color: cosmic::iced::Color::from(cosmic.accent.base),
346+
},
347+
icon,
348+
placeholder,
349+
value,
350+
selection,
351+
}
352+
}
353+
}
354+
}

0 commit comments

Comments
 (0)