Add Select All
This commit is contained in:
parent
e76b63a039
commit
054d4f3df9
4 changed files with 32 additions and 8 deletions
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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue