From 563b8109f0cdadeeb6f6b12f49e93f591bf94e34 Mon Sep 17 00:00:00 2001 From: pml68 Date: Tue, 14 Jan 2025 18:43:06 +0100 Subject: feat: add iced_custom_highlighter --- Cargo.lock | 10 ++++++++++ Cargo.toml | 4 ++++ src/panes/code_view.rs | 12 +++++------- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a638ff4..af254a0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2003,6 +2003,7 @@ dependencies = [ "fxhash", "iced", "iced_anim", + "iced_custom_highlighter", "iced_drop", "iced_fontello", "rfd", @@ -2038,6 +2039,15 @@ dependencies = [ "web-time", ] +[[package]] +name = "iced_custom_highlighter" +version = "0.1.0" +source = "git+https://github.com/pml68/iced_custom_highlighter?branch=fix%2Ftemp-update-on-theme-changed#f780df7c0c65417731e9cd34143ae902796b7bbf" +dependencies = [ + "iced_widget", + "syntect", +] + [[package]] name = "iced_drop" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 1f97ff3..f83f3c8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,6 +31,10 @@ rev = "d259ec4dff098852d995d3bcaa5551a88330636f" [target.'cfg(target_os = "macos")'.dependencies] xdg = "2.5.2" +[dependencies.iced_custom_highlighter] +git = "https://github.com/pml68/iced_custom_highlighter" +branch = "fix/temp-update-on-theme-changed" + [build-dependencies] iced_fontello = "0.13.1" diff --git a/src/panes/code_view.rs b/src/panes/code_view.rs index f545157..b328722 100644 --- a/src/panes/code_view.rs +++ b/src/panes/code_view.rs @@ -1,5 +1,7 @@ use iced::widget::{button, pane_grid, row, text, text_editor, Space}; use iced::{Alignment, Font, Length, Theme}; +use iced_custom_highlighter::{Highlight, Highlighter, Settings}; + use super::style; use crate::icon::copy; use crate::types::{DesignerPage, Message}; @@ -29,14 +31,10 @@ pub fn view( pane_grid::Content::new( text_editor(editor_content) .on_action(Message::EditorAction) - .highlight( - "rs", - if theme.to_string().contains("Dark") { - highlighter::Theme::SolarizedDark - } else { - highlighter::Theme::InspiredGitHub - }, .font(Font::MONOSPACE) + .highlight_with::( + Settings::new(vec![], Highlight::default_style, theme, "rs"), + Highlight::to_format, ) .height(Length::Fill) .padding(20), -- cgit v1.2.3