Implement tab width config
This commit is contained in:
parent
67d2e4adb7
commit
b1c6505832
5 changed files with 25 additions and 5 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
|
@ -897,7 +897,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cosmic-text"
|
name = "cosmic-text"
|
||||||
version = "0.10.0"
|
version = "0.10.0"
|
||||||
source = "git+https://github.com/pop-os/cosmic-text?branch=vi-editor#8024cbe504fbe3b73df4222b2a9d64e7d32d5c6d"
|
source = "git+https://github.com/pop-os/cosmic-text?branch=vi-editor#1207fd6d804b76b52137a368a58b27150eb865b8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cosmic_undo_2",
|
"cosmic_undo_2",
|
||||||
"fontdb 0.16.0",
|
"fontdb 0.16.0",
|
||||||
|
|
|
||||||
|
|
@ -146,6 +146,7 @@ pub struct Config {
|
||||||
pub font_size: u16,
|
pub font_size: u16,
|
||||||
pub syntax_theme_dark: String,
|
pub syntax_theme_dark: String,
|
||||||
pub syntax_theme_light: String,
|
pub syntax_theme_light: String,
|
||||||
|
pub tab_width: u16,
|
||||||
pub vim_bindings: bool,
|
pub vim_bindings: bool,
|
||||||
pub word_wrap: bool,
|
pub word_wrap: bool,
|
||||||
pub keybinds: HashMap<KeyBind, Action>,
|
pub keybinds: HashMap<KeyBind, Action>,
|
||||||
|
|
@ -159,6 +160,7 @@ impl Default for Config {
|
||||||
font_size: 14,
|
font_size: 14,
|
||||||
syntax_theme_dark: "gruvbox-dark".to_string(),
|
syntax_theme_dark: "gruvbox-dark".to_string(),
|
||||||
syntax_theme_light: "gruvbox-light".to_string(),
|
syntax_theme_light: "gruvbox-light".to_string(),
|
||||||
|
tab_width: 4,
|
||||||
vim_bindings: false,
|
vim_bindings: false,
|
||||||
word_wrap: false,
|
word_wrap: false,
|
||||||
keybinds: KeyBind::load(),
|
keybinds: KeyBind::load(),
|
||||||
|
|
|
||||||
|
|
@ -133,6 +133,7 @@ pub enum Message {
|
||||||
TabActivate(segmented_button::Entity),
|
TabActivate(segmented_button::Entity),
|
||||||
TabChanged(segmented_button::Entity),
|
TabChanged(segmented_button::Entity),
|
||||||
TabClose(segmented_button::Entity),
|
TabClose(segmented_button::Entity),
|
||||||
|
TabWidth(u16),
|
||||||
Todo,
|
Todo,
|
||||||
ToggleContextPage(ContextPage),
|
ToggleContextPage(ContextPage),
|
||||||
ToggleWordWrap,
|
ToggleWordWrap,
|
||||||
|
|
@ -827,6 +828,10 @@ impl Application for App {
|
||||||
|
|
||||||
return self.update_tab();
|
return self.update_tab();
|
||||||
}
|
}
|
||||||
|
Message::TabWidth(tab_width) => {
|
||||||
|
self.config.tab_width = tab_width;
|
||||||
|
return self.save_config();
|
||||||
|
}
|
||||||
Message::Todo => {
|
Message::Todo => {
|
||||||
log::warn!("TODO");
|
log::warn!("TODO");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
20
src/menu.rs
20
src/menu.rs
|
|
@ -92,6 +92,14 @@ pub fn menu_bar<'a>(config: &Config) -> Element<'a, Message> {
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let menu_tab_width = |tab_width: u16| {
|
||||||
|
menu_checkbox(
|
||||||
|
fl!("tab-width", tab_width = tab_width),
|
||||||
|
config.tab_width == tab_width,
|
||||||
|
Message::TabWidth(tab_width),
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
MenuBar::new(vec![
|
MenuBar::new(vec![
|
||||||
MenuTree::with_children(
|
MenuTree::with_children(
|
||||||
menu_root(fl!("file")),
|
menu_root(fl!("file")),
|
||||||
|
|
@ -154,10 +162,14 @@ pub fn menu_bar<'a>(config: &Config) -> Element<'a, Message> {
|
||||||
vec![
|
vec![
|
||||||
menu_item(fl!("automatic-indentation"), Message::Todo),
|
menu_item(fl!("automatic-indentation"), Message::Todo),
|
||||||
MenuTree::new(horizontal_rule(1)),
|
MenuTree::new(horizontal_rule(1)),
|
||||||
menu_item(fl!("tab-width", tab_width = 1), Message::Todo),
|
menu_tab_width(1),
|
||||||
menu_item(fl!("tab-width", tab_width = 2), Message::Todo),
|
menu_tab_width(2),
|
||||||
menu_item(fl!("tab-width", tab_width = 4), Message::Todo),
|
menu_tab_width(3),
|
||||||
menu_item(fl!("tab-width", tab_width = 8), Message::Todo),
|
menu_tab_width(4),
|
||||||
|
menu_tab_width(5),
|
||||||
|
menu_tab_width(6),
|
||||||
|
menu_tab_width(7),
|
||||||
|
menu_tab_width(8),
|
||||||
MenuTree::new(horizontal_rule(1)),
|
MenuTree::new(horizontal_rule(1)),
|
||||||
menu_item(fl!("convert-indentation-to-spaces"), Message::Todo),
|
menu_item(fl!("convert-indentation-to-spaces"), Message::Todo),
|
||||||
menu_item(fl!("convert-indentation-to-tabs"), Message::Todo),
|
menu_item(fl!("convert-indentation-to-tabs"), Message::Todo),
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,7 @@ impl Tab {
|
||||||
let mut font_system = FONT_SYSTEM.lock().unwrap();
|
let mut font_system = FONT_SYSTEM.lock().unwrap();
|
||||||
let mut editor = editor.borrow_with(&mut font_system);
|
let mut editor = editor.borrow_with(&mut font_system);
|
||||||
editor.set_passthrough(!config.vim_bindings);
|
editor.set_passthrough(!config.vim_bindings);
|
||||||
|
editor.set_tab_width(config.tab_width);
|
||||||
editor.buffer_mut().set_wrap(if config.word_wrap {
|
editor.buffer_mut().set_wrap(if config.word_wrap {
|
||||||
Wrap::Word
|
Wrap::Word
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue