diff --git a/lapce-core/src/syntax.rs b/lapce-core/src/syntax.rs index 42831e85..f6c5dcc6 100644 --- a/lapce-core/src/syntax.rs +++ b/lapce-core/src/syntax.rs @@ -37,6 +37,21 @@ pub struct Syntax { pub styles: Option>>, } +impl std::fmt::Debug for Syntax { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("Syntax") + .field("rev", &self.rev) + .field("language", &self.language) + .field("text", &self.text) + .field("tree", &self.tree) + .field("normal_lines", &self.normal_lines) + .field("line_height", &self.line_height) + .field("lens_height", &self.lens_height) + .field("styles", &self.styles) + .finish() + } +} + impl Syntax { pub fn init(path: &Path) -> Option { LapceLanguage::from_path(path).map(|l| Syntax { diff --git a/lapce-data/src/command.rs b/lapce-data/src/command.rs index e7dc4d13..78ef2347 100644 --- a/lapce-data/src/command.rs +++ b/lapce-data/src/command.rs @@ -560,6 +560,7 @@ pub enum EnsureVisiblePosition { CenterOfWindow, } +#[derive(Debug)] pub enum LapceUICommand { InitChildren, InitTerminalPanel(bool), @@ -704,4 +705,7 @@ pub enum LapceUICommand { GotoDefinition(WidgetId, usize, EditorLocationNew), PaletteReferences(usize, Vec), GotoLocation(Location), + ActiveFileChanged { + path: Option, + }, } diff --git a/lapce-ui/src/editor/tab.rs b/lapce-ui/src/editor/tab.rs index a225d9eb..c365b9fe 100644 --- a/lapce-ui/src/editor/tab.rs +++ b/lapce-ui/src/editor/tab.rs @@ -6,14 +6,15 @@ Rect, RenderContext, Size, Target, UpdateCtx, Widget, WidgetId, WidgetPod, }; use lapce_data::{ + buffer::BufferContent, command::{LapceUICommand, LAPCE_UI_COMMAND}, config::LapceTheme, data::{ DragContent, EditorTabChild, LapceEditorTabData, LapceTabData, SplitContent, }, + db::EditorTabChildInfo, editor::TabRect, split::{SplitDirection, SplitMoveDirection}, - }; use crate::editor::{ @@ -343,6 +344,30 @@ fn event( )); return; } + LapceUICommand::EnsureEditorTabActiveVisble => { + if let Some(tab) = + data.main_split.editor_tabs.get(&self.widget_id) + { + let active = &tab.children[tab.active]; + let EditorTabChildInfo::Editor(info) = + active.child_info(data, 4); + + ctx.submit_command(Command::new( + LAPCE_UI_COMMAND, + LapceUICommand::ActiveFileChanged { + path: if let BufferContent::File(path) = + info.content + { + Some(path.clone()) + } else { + None + }, + }, + Target::Widget(data.file_explorer.widget_id), + )); + return; + } + } _ => (), } } diff --git a/lapce-ui/src/explorer.rs b/lapce-ui/src/explorer.rs index e86993da..7087663c 100644 --- a/lapce-ui/src/explorer.rs +++ b/lapce-ui/src/explorer.rs @@ -367,6 +367,16 @@ fn event( data: &mut LapceTabData, _env: &Env, ) { + match event { + Event::Command(cmd) if cmd.is(LAPCE_UI_COMMAND) => { + let command = cmd.get_unchecked(LAPCE_UI_COMMAND); + + if let LapceUICommand::ActiveFileChanged { path } = command { + println!("{path:?}"); + } + } + _ => {} + } if !ctx.is_hot() { return; }