feat: add highlighting to editor

This commit is contained in:
Stevan Freeborn
2026-01-24 21:24:32 -06:00
parent cfad6c883c
commit 75ab718655
3 changed files with 32 additions and 24 deletions
+1
View File
@@ -0,0 +1 @@
tab_spaces = 2
+3 -3
View File
@@ -1,5 +1,5 @@
use iced::{
Element, Length, Theme,
Element, Length, Theme, highlighter,
widget::{container, markdown, row, text_editor},
};
@@ -9,6 +9,7 @@ pub fn view<'a>(file: &'a File, mode: Mode, font_size: u32) -> Element<'a, Messa
match mode {
Mode::Edit => {
let editor = text_editor(file.content())
.highlight(file.extension().unwrap_or("txt"), highlighter::Theme::Base16Ocean)
.size(font_size)
.height(Length::Fill)
.on_action(Message::Edit);
@@ -21,8 +22,7 @@ pub fn view<'a>(file: &'a File, mode: Mode, font_size: u32) -> Element<'a, Messa
let settings = markdown::Settings::with_text_size(font_size, style);
let markdown_preview =
markdown::view(file.markdown(), settings).map(Message::LinkClicked);
let markdown_preview = markdown::view(file.markdown(), settings).map(Message::LinkClicked);
container(row![markdown_preview])
.height(Length::Fill)
+8 -1
View File
@@ -1,4 +1,4 @@
use std::path::PathBuf;
use std::{ffi, path::{Path, PathBuf}};
use iced::widget::{markdown, text_editor};
@@ -58,6 +58,13 @@ impl File {
self.path = path;
}
pub fn extension(&self) -> Option<&str> {
self.path
.as_deref()
.and_then(Path::extension)
.and_then(ffi::OsStr::to_str)
}
pub fn display_name(&self) -> &str {
self.path
.as_deref()