mirror of https://github.com/lapce/lapce.git
Create command to select active file in file_explorer
This commit is contained in:
parent
d57f85892a
commit
f6d801ecfc
|
@ -37,6 +37,21 @@ pub struct Syntax {
|
|||
pub styles: Option<Arc<Spans<Style>>>,
|
||||
}
|
||||
|
||||
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<Syntax> {
|
||||
LapceLanguage::from_path(path).map(|l| Syntax {
|
||||
|
|
|
@ -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<Location>),
|
||||
GotoLocation(Location),
|
||||
ActiveFileChanged {
|
||||
path: Option<PathBuf>,
|
||||
},
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue