Add Select All
This commit is contained in:
parent
e76b63a039
commit
054d4f3df9
4 changed files with 32 additions and 8 deletions
|
|
@ -48,6 +48,7 @@ redo = Redo
|
|||
cut = Cut
|
||||
copy = Copy
|
||||
paste = Paste
|
||||
select-all = Select All
|
||||
find = Find
|
||||
replace = Replace
|
||||
spell-check = Spell check...
|
||||
|
|
|
|||
|
|
@ -12,14 +12,15 @@ pub const CONFIG_VERSION: u64 = 1;
|
|||
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
|
||||
pub enum Action {
|
||||
Cut,
|
||||
Copy,
|
||||
Paste,
|
||||
Cut,
|
||||
NewFile,
|
||||
NewWindow,
|
||||
OpenFileDialog,
|
||||
Save,
|
||||
Paste,
|
||||
Quit,
|
||||
Save,
|
||||
SelectAll,
|
||||
ToggleSettingsPage,
|
||||
ToggleWordWrap,
|
||||
}
|
||||
|
|
@ -27,14 +28,15 @@ pub enum Action {
|
|||
impl Action {
|
||||
pub fn message(&self) -> Message {
|
||||
match self {
|
||||
Self::Cut => Message::Cut,
|
||||
Self::Copy => Message::Copy,
|
||||
Self::Paste => Message::Paste,
|
||||
Self::Cut => Message::Cut,
|
||||
Self::NewFile => Message::NewFile,
|
||||
Self::NewWindow => Message::NewWindow,
|
||||
Self::OpenFileDialog => Message::OpenFileDialog,
|
||||
Self::Save => Message::Save,
|
||||
Self::Paste => Message::Paste,
|
||||
Self::Quit => Message::Quit,
|
||||
Self::Save => Message::Save,
|
||||
Self::SelectAll => Message::SelectAll,
|
||||
Self::ToggleSettingsPage => Message::ToggleContextPage(ContextPage::Settings),
|
||||
Self::ToggleWordWrap => Message::ToggleWordWrap,
|
||||
}
|
||||
|
|
@ -78,8 +80,9 @@ impl KeyBind {
|
|||
bind!([Ctrl], N, NewFile);
|
||||
bind!([Ctrl, Shift], N, NewWindow);
|
||||
bind!([Ctrl], O, OpenFileDialog);
|
||||
bind!([Ctrl], S, Save);
|
||||
bind!([Ctrl], Q, Quit);
|
||||
bind!([Ctrl], S, Save);
|
||||
bind!([Ctrl], A, SelectAll);
|
||||
bind!([Ctrl], Comma, ToggleSettingsPage);
|
||||
bind!([Alt], Z, ToggleWordWrap);
|
||||
|
||||
|
|
|
|||
21
src/main.rs
21
src/main.rs
|
|
@ -13,7 +13,7 @@ use cosmic::{
|
|||
widget::{self, button, icon, nav_bar, segmented_button, view_switcher},
|
||||
ApplicationExt, Element,
|
||||
};
|
||||
use cosmic_text::{Edit, Family, FontSystem, SwashCache, SyntaxSystem, ViMode};
|
||||
use cosmic_text::{Cursor, Edit, Family, FontSystem, SwashCache, SyntaxSystem, ViMode};
|
||||
use std::{
|
||||
env, fs,
|
||||
path::{Path, PathBuf},
|
||||
|
|
@ -87,6 +87,7 @@ pub enum Message {
|
|||
PasteValue(String),
|
||||
Quit,
|
||||
Save,
|
||||
SelectAll,
|
||||
SyntaxTheme(usize, bool),
|
||||
TabActivate(segmented_button::Entity),
|
||||
TabClose(segmented_button::Entity),
|
||||
|
|
@ -668,6 +669,7 @@ impl cosmic::Application for App {
|
|||
tab.save();
|
||||
}
|
||||
None => {
|
||||
//TODO: disable save button?
|
||||
log::warn!("TODO: NO TAB OPEN");
|
||||
}
|
||||
}
|
||||
|
|
@ -676,6 +678,23 @@ impl cosmic::Application for App {
|
|||
self.tab_model.text_set(self.tab_model.active(), title);
|
||||
}
|
||||
}
|
||||
Message::SelectAll => {
|
||||
match self.active_tab_mut() {
|
||||
Some(tab) => {
|
||||
let mut editor = tab.editor.lock().unwrap();
|
||||
|
||||
// Set cursor to lowest possible value
|
||||
editor.set_cursor(Cursor::new(0, 0));
|
||||
|
||||
// Set selection end to highest possible value
|
||||
let buffer = editor.buffer();
|
||||
let last_line = buffer.lines.len().saturating_sub(1);
|
||||
let last_index = buffer.lines[last_line].text().len();
|
||||
editor.set_select_opt(Some(Cursor::new(last_line, last_index)));
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
Message::SyntaxTheme(index, dark) => match self.theme_names.get(index) {
|
||||
Some(theme_name) => {
|
||||
if dark {
|
||||
|
|
|
|||
|
|
@ -130,6 +130,7 @@ pub fn menu_bar<'a>(config: &Config) -> Element<'a, Message> {
|
|||
menu_item(fl!("cut"), Message::Cut),
|
||||
menu_item(fl!("copy"), Message::Copy),
|
||||
menu_item(fl!("paste"), Message::Paste),
|
||||
menu_item(fl!("select-all"), Message::SelectAll),
|
||||
MenuTree::new(horizontal_rule(1)),
|
||||
menu_key(fl!("find"), "Ctrl + F", Message::Todo),
|
||||
menu_key(fl!("replace"), "Ctrl + H", Message::Todo),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue