[tui] Store SyntaxSet in the Editor.
This commit is contained in:
parent
d2846e1e4e
commit
2713d29285
@ -19,6 +19,7 @@ pub struct Editor {
|
|||||||
pub state: EditorState,
|
pub state: EditorState,
|
||||||
pub event_handler: EditorEventHandler,
|
pub event_handler: EditorEventHandler,
|
||||||
pub file_path: Option<std::path::PathBuf>,
|
pub file_path: Option<std::path::PathBuf>,
|
||||||
|
syntax_set: SyntaxSet,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Editor {
|
impl Editor {
|
||||||
@ -27,6 +28,7 @@ impl Editor {
|
|||||||
state: EditorState::default(),
|
state: EditorState::default(),
|
||||||
event_handler: EditorEventHandler::default(),
|
event_handler: EditorEventHandler::default(),
|
||||||
file_path: None,
|
file_path: None,
|
||||||
|
syntax_set: SyntaxSet::load_defaults_nonewlines(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,10 +61,11 @@ impl Widget for &mut Editor {
|
|||||||
.and_then(|p| p.extension())
|
.and_then(|p| p.extension())
|
||||||
.map(|e| e.to_str().unwrap_or("md"))
|
.map(|e| e.to_str().unwrap_or("md"))
|
||||||
.unwrap_or("md");
|
.unwrap_or("md");
|
||||||
let lang_name = SyntaxSet::load_defaults_nonewlines()
|
let lang_name = self
|
||||||
|
.syntax_set
|
||||||
.find_syntax_by_extension(lang)
|
.find_syntax_by_extension(lang)
|
||||||
.map(|s| s.name.to_string())
|
.map(|s| s.name.to_string())
|
||||||
.unwrap_or_else(|| "Unknown".to_string());
|
.unwrap_or("Unknown".to_string());
|
||||||
|
|
||||||
EditorView::new(&mut self.state)
|
EditorView::new(&mut self.state)
|
||||||
.wrap(true)
|
.wrap(true)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user