Add auto-indent support
This commit is contained in:
parent
b1c6505832
commit
f0d9bc06e1
5 changed files with 14 additions and 2 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
|
@ -897,7 +897,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "cosmic-text"
|
||||
version = "0.10.0"
|
||||
source = "git+https://github.com/pop-os/cosmic-text?branch=vi-editor#1207fd6d804b76b52137a368a58b27150eb865b8"
|
||||
source = "git+https://github.com/pop-os/cosmic-text?branch=vi-editor#7d21045b2f93a382f7ddea209b8f28204888d418"
|
||||
dependencies = [
|
||||
"cosmic_undo_2",
|
||||
"fontdb 0.16.0",
|
||||
|
|
|
|||
|
|
@ -142,6 +142,7 @@ impl fmt::Display for KeyBind {
|
|||
#[derive(Clone, CosmicConfigEntry, Debug, Deserialize, Eq, PartialEq, Serialize)]
|
||||
pub struct Config {
|
||||
pub app_theme: AppTheme,
|
||||
pub auto_indent: bool,
|
||||
pub font_name: String,
|
||||
pub font_size: u16,
|
||||
pub syntax_theme_dark: String,
|
||||
|
|
@ -156,6 +157,7 @@ impl Default for Config {
|
|||
fn default() -> Self {
|
||||
Self {
|
||||
app_theme: AppTheme::System,
|
||||
auto_indent: true,
|
||||
font_name: "Fira Mono".to_string(),
|
||||
font_size: 14,
|
||||
syntax_theme_dark: "gruvbox-dark".to_string(),
|
||||
|
|
|
|||
|
|
@ -135,6 +135,7 @@ pub enum Message {
|
|||
TabClose(segmented_button::Entity),
|
||||
TabWidth(u16),
|
||||
Todo,
|
||||
ToggleAutoIndent,
|
||||
ToggleContextPage(ContextPage),
|
||||
ToggleWordWrap,
|
||||
Undo,
|
||||
|
|
@ -835,6 +836,10 @@ impl Application for App {
|
|||
Message::Todo => {
|
||||
log::warn!("TODO");
|
||||
}
|
||||
Message::ToggleAutoIndent => {
|
||||
self.config.auto_indent = !self.config.auto_indent;
|
||||
return self.save_config();
|
||||
}
|
||||
Message::ToggleContextPage(context_page) => {
|
||||
if self.context_page == context_page {
|
||||
self.core.window.show_context = !self.core.window.show_context;
|
||||
|
|
|
|||
|
|
@ -160,7 +160,11 @@ pub fn menu_bar<'a>(config: &Config) -> Element<'a, Message> {
|
|||
MenuTree::with_children(
|
||||
menu_folder(fl!("indentation")),
|
||||
vec![
|
||||
menu_item(fl!("automatic-indentation"), Message::Todo),
|
||||
menu_checkbox(
|
||||
fl!("automatic-indentation"),
|
||||
config.auto_indent,
|
||||
Message::ToggleAutoIndent,
|
||||
),
|
||||
MenuTree::new(horizontal_rule(1)),
|
||||
menu_tab_width(1),
|
||||
menu_tab_width(2),
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ impl Tab {
|
|||
let mut editor = self.editor.lock().unwrap();
|
||||
let mut font_system = FONT_SYSTEM.lock().unwrap();
|
||||
let mut editor = editor.borrow_with(&mut font_system);
|
||||
editor.set_auto_indent(config.auto_indent);
|
||||
editor.set_passthrough(!config.vim_bindings);
|
||||
editor.set_tab_width(config.tab_width);
|
||||
editor.buffer_mut().set_wrap(if config.word_wrap {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue