Update to vi-editor branch of cosmic-text
This commit is contained in:
parent
b59710ddc4
commit
33f29f4796
3 changed files with 950 additions and 91 deletions
966
Cargo.lock
generated
966
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
11
Cargo.toml
11
Cargo.toml
|
|
@ -14,12 +14,15 @@ rfd = "0.12.0"
|
||||||
|
|
||||||
[dependencies.cosmic-text]
|
[dependencies.cosmic-text]
|
||||||
git = "https://github.com/pop-os/cosmic-text"
|
git = "https://github.com/pop-os/cosmic-text"
|
||||||
features = ["syntect"]
|
branch = "vi-editor"
|
||||||
|
features = ["syntect", "vi"]
|
||||||
|
#path = "../cosmic-text"
|
||||||
|
|
||||||
[dependencies.libcosmic]
|
[dependencies.libcosmic]
|
||||||
git = "https://github.com/pop-os/libcosmic"
|
git = "https://github.com/pop-os/libcosmic"
|
||||||
features = ["wayland"]
|
default-features = false
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = ["wayland"]
|
||||||
vi = ["cosmic-text/vi"]
|
wayland = ["libcosmic/wayland"]
|
||||||
|
winit = ["libcosmic/winit"]
|
||||||
|
|
|
||||||
64
src/main.rs
64
src/main.rs
|
|
@ -7,10 +7,12 @@ use cosmic::{
|
||||||
widget::{column, row, text},
|
widget::{column, row, text},
|
||||||
Alignment, Length, Limits,
|
Alignment, Length, Limits,
|
||||||
},
|
},
|
||||||
widget::{icon, segmented_button, view_switcher},
|
widget::{self, icon, segmented_button, view_switcher},
|
||||||
ApplicationExt, Element,
|
ApplicationExt, Element,
|
||||||
};
|
};
|
||||||
use cosmic_text::{Attrs, Buffer, Edit, FontSystem, Metrics, SyntaxEditor, SyntaxSystem};
|
use cosmic_text::{
|
||||||
|
Attrs, Buffer, Edit, FontSystem, Metrics, SyntaxEditor, SyntaxSystem, ViEditor, ViMode,
|
||||||
|
};
|
||||||
use std::{env, fs, path::PathBuf, sync::Mutex};
|
use std::{env, fs, path::PathBuf, sync::Mutex};
|
||||||
|
|
||||||
use self::menu_list::MenuList;
|
use self::menu_list::MenuList;
|
||||||
|
|
@ -36,8 +38,7 @@ static FONT_SIZES: &'static [Metrics] = &[
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
|
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
|
||||||
|
|
||||||
let settings = Settings::default()
|
let settings = Settings::default().size_limits(Limits::NONE.min_width(400.0).min_height(200.0));
|
||||||
.size_limits(Limits::NONE.min_width(400.0).min_height(200.0));
|
|
||||||
let flags = ();
|
let flags = ();
|
||||||
cosmic::app::run::<App>(settings, flags)?;
|
cosmic::app::run::<App>(settings, flags)?;
|
||||||
|
|
||||||
|
|
@ -47,10 +48,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
pub struct Tab {
|
pub struct Tab {
|
||||||
path_opt: Option<PathBuf>,
|
path_opt: Option<PathBuf>,
|
||||||
attrs: Attrs<'static>,
|
attrs: Attrs<'static>,
|
||||||
#[cfg(not(feature = "vi"))]
|
editor: Mutex<ViEditor<'static>>,
|
||||||
editor: Mutex<SyntaxEditor<'static>>,
|
|
||||||
#[cfg(feature = "vi")]
|
|
||||||
editor: Mutex<cosmic_text::ViEditor<'static>>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Tab {
|
impl Tab {
|
||||||
|
|
@ -64,8 +62,8 @@ impl Tab {
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
#[cfg(feature = "vi")]
|
let mut editor = ViEditor::new(editor);
|
||||||
let editor = cosmic_text::ViEditor::new(editor);
|
editor.set_passthrough(false);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
path_opt: None,
|
path_opt: None,
|
||||||
|
|
@ -297,21 +295,49 @@ impl cosmic::Application for App {
|
||||||
.padding(4)
|
.padding(4)
|
||||||
.spacing(16);
|
.spacing(16);
|
||||||
|
|
||||||
let tab_bar = view_switcher::horizontal(&self.tab_model)
|
let mut tab_column = widget::column::with_capacity(3).padding([0, 16]);
|
||||||
.on_activate(Message::TabActivate)
|
|
||||||
.on_close(Message::TabClose)
|
|
||||||
.width(Length::Shrink);
|
|
||||||
|
|
||||||
let active_tab: Element<_> = match self.active_tab() {
|
tab_column = tab_column.push(
|
||||||
Some(tab) => text_box(&tab.editor).padding(8).into(),
|
view_switcher::horizontal(&self.tab_model)
|
||||||
|
.on_activate(Message::TabActivate)
|
||||||
|
.on_close(Message::TabClose)
|
||||||
|
.width(Length::Shrink),
|
||||||
|
);
|
||||||
|
|
||||||
|
match self.active_tab() {
|
||||||
|
Some(tab) => {
|
||||||
|
tab_column = tab_column.push(text_box(&tab.editor).padding(8));
|
||||||
|
let status = match tab.editor.lock().unwrap().mode() {
|
||||||
|
ViMode::Passthrough => {
|
||||||
|
//TODO: status line
|
||||||
|
String::new()
|
||||||
|
}
|
||||||
|
ViMode::Normal => {
|
||||||
|
//TODO: status line
|
||||||
|
String::new()
|
||||||
|
}
|
||||||
|
ViMode::Insert => {
|
||||||
|
format!("-- INSERT --")
|
||||||
|
}
|
||||||
|
ViMode::Command { value } => {
|
||||||
|
format!(":{value}|")
|
||||||
|
}
|
||||||
|
ViMode::Search { value, forwards } => {
|
||||||
|
if *forwards {
|
||||||
|
format!("/{value}|")
|
||||||
|
} else {
|
||||||
|
format!("?{value}|")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
tab_column = tab_column.push(text(status).font(cosmic::font::Font::MONOSPACE));
|
||||||
|
}
|
||||||
None => {
|
None => {
|
||||||
log::warn!("TODO: No tab open");
|
log::warn!("TODO: No tab open");
|
||||||
text("no tab active").into()
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let content: Element<_> =
|
let content: Element<_> = column![menu_bar, tab_column].into();
|
||||||
column![menu_bar, column![tab_bar, active_tab,].padding([0, 16])].into();
|
|
||||||
|
|
||||||
// Uncomment to debug layout:
|
// Uncomment to debug layout:
|
||||||
//content.explain(Color::WHITE)
|
//content.explain(Color::WHITE)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue