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
|
cut = Cut
|
||||||
copy = Copy
|
copy = Copy
|
||||||
paste = Paste
|
paste = Paste
|
||||||
|
select-all = Select All
|
||||||
find = Find
|
find = Find
|
||||||
replace = Replace
|
replace = Replace
|
||||||
spell-check = Spell check...
|
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)]
|
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
|
||||||
pub enum Action {
|
pub enum Action {
|
||||||
Cut,
|
|
||||||
Copy,
|
Copy,
|
||||||
Paste,
|
Cut,
|
||||||
NewFile,
|
NewFile,
|
||||||
NewWindow,
|
NewWindow,
|
||||||
OpenFileDialog,
|
OpenFileDialog,
|
||||||
Save,
|
Paste,
|
||||||
Quit,
|
Quit,
|
||||||
|
Save,
|
||||||
|
SelectAll,
|
||||||
ToggleSettingsPage,
|
ToggleSettingsPage,
|
||||||
ToggleWordWrap,
|
ToggleWordWrap,
|
||||||
}
|
}
|
||||||
|
|
@ -27,14 +28,15 @@ pub enum Action {
|
||||||
impl Action {
|
impl Action {
|
||||||
pub fn message(&self) -> Message {
|
pub fn message(&self) -> Message {
|
||||||
match self {
|
match self {
|
||||||
Self::Cut => Message::Cut,
|
|
||||||
Self::Copy => Message::Copy,
|
Self::Copy => Message::Copy,
|
||||||
Self::Paste => Message::Paste,
|
Self::Cut => Message::Cut,
|
||||||
Self::NewFile => Message::NewFile,
|
Self::NewFile => Message::NewFile,
|
||||||
Self::NewWindow => Message::NewWindow,
|
Self::NewWindow => Message::NewWindow,
|
||||||
Self::OpenFileDialog => Message::OpenFileDialog,
|
Self::OpenFileDialog => Message::OpenFileDialog,
|
||||||
Self::Save => Message::Save,
|
Self::Paste => Message::Paste,
|
||||||
Self::Quit => Message::Quit,
|
Self::Quit => Message::Quit,
|
||||||
|
Self::Save => Message::Save,
|
||||||
|
Self::SelectAll => Message::SelectAll,
|
||||||
Self::ToggleSettingsPage => Message::ToggleContextPage(ContextPage::Settings),
|
Self::ToggleSettingsPage => Message::ToggleContextPage(ContextPage::Settings),
|
||||||
Self::ToggleWordWrap => Message::ToggleWordWrap,
|
Self::ToggleWordWrap => Message::ToggleWordWrap,
|
||||||
}
|
}
|
||||||
|
|
@ -78,8 +80,9 @@ impl KeyBind {
|
||||||
bind!([Ctrl], N, NewFile);
|
bind!([Ctrl], N, NewFile);
|
||||||
bind!([Ctrl, Shift], N, NewWindow);
|
bind!([Ctrl, Shift], N, NewWindow);
|
||||||
bind!([Ctrl], O, OpenFileDialog);
|
bind!([Ctrl], O, OpenFileDialog);
|
||||||
bind!([Ctrl], S, Save);
|
|
||||||
bind!([Ctrl], Q, Quit);
|
bind!([Ctrl], Q, Quit);
|
||||||
|
bind!([Ctrl], S, Save);
|
||||||
|
bind!([Ctrl], A, SelectAll);
|
||||||
bind!([Ctrl], Comma, ToggleSettingsPage);
|
bind!([Ctrl], Comma, ToggleSettingsPage);
|
||||||
bind!([Alt], Z, ToggleWordWrap);
|
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},
|
widget::{self, button, icon, nav_bar, segmented_button, view_switcher},
|
||||||
ApplicationExt, Element,
|
ApplicationExt, Element,
|
||||||
};
|
};
|
||||||
use cosmic_text::{Edit, Family, FontSystem, SwashCache, SyntaxSystem, ViMode};
|
use cosmic_text::{Cursor, Edit, Family, FontSystem, SwashCache, SyntaxSystem, ViMode};
|
||||||
use std::{
|
use std::{
|
||||||
env, fs,
|
env, fs,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
|
|
@ -87,6 +87,7 @@ pub enum Message {
|
||||||
PasteValue(String),
|
PasteValue(String),
|
||||||
Quit,
|
Quit,
|
||||||
Save,
|
Save,
|
||||||
|
SelectAll,
|
||||||
SyntaxTheme(usize, bool),
|
SyntaxTheme(usize, bool),
|
||||||
TabActivate(segmented_button::Entity),
|
TabActivate(segmented_button::Entity),
|
||||||
TabClose(segmented_button::Entity),
|
TabClose(segmented_button::Entity),
|
||||||
|
|
@ -668,6 +669,7 @@ impl cosmic::Application for App {
|
||||||
tab.save();
|
tab.save();
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
|
//TODO: disable save button?
|
||||||
log::warn!("TODO: NO TAB OPEN");
|
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);
|
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) {
|
Message::SyntaxTheme(index, dark) => match self.theme_names.get(index) {
|
||||||
Some(theme_name) => {
|
Some(theme_name) => {
|
||||||
if dark {
|
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!("cut"), Message::Cut),
|
||||||
menu_item(fl!("copy"), Message::Copy),
|
menu_item(fl!("copy"), Message::Copy),
|
||||||
menu_item(fl!("paste"), Message::Paste),
|
menu_item(fl!("paste"), Message::Paste),
|
||||||
|
menu_item(fl!("select-all"), Message::SelectAll),
|
||||||
MenuTree::new(horizontal_rule(1)),
|
MenuTree::new(horizontal_rule(1)),
|
||||||
menu_key(fl!("find"), "Ctrl + F", Message::Todo),
|
menu_key(fl!("find"), "Ctrl + F", Message::Todo),
|
||||||
menu_key(fl!("replace"), "Ctrl + H", Message::Todo),
|
menu_key(fl!("replace"), "Ctrl + H", Message::Todo),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue