esc on settings

This commit is contained in:
Dongdong Zhou 2022-03-24 10:11:58 +00:00
parent 36d2a854c5
commit 7a886a3093
4 changed files with 38 additions and 6 deletions

View File

@ -574,6 +574,8 @@ pub enum LapceUICommand {
CancelPalette, CancelPalette,
ShowCodeActions, ShowCodeActions,
CancelCodeActions, CancelCodeActions,
Hide,
ResignFocus,
Focus, Focus,
EnsureEditorTabActiveVisble, EnsureEditorTabActiveVisble,
FocusSourceControl, FocusSourceControl,

View File

@ -1,7 +1,7 @@
use druid::{Env, EventCtx, Modifiers, WidgetId}; use druid::{Command, Env, EventCtx, Modifiers, Target, WidgetId};
use crate::{ use crate::{
command::{CommandExecuted, LapceCommand}, command::{CommandExecuted, LapceCommand, LapceUICommand, LAPCE_UI_COMMAND},
keypress::KeyPressFocus, keypress::KeyPressFocus,
state::Mode, state::Mode,
}; };
@ -36,14 +36,18 @@ fn check_condition(&self, condition: &str) -> bool {
fn run_command( fn run_command(
&mut self, &mut self,
_ctx: &mut EventCtx, ctx: &mut EventCtx,
command: &LapceCommand, command: &LapceCommand,
_count: Option<usize>, _count: Option<usize>,
_mods: Modifiers, _mods: Modifiers,
_env: &Env, _env: &Env,
) -> CommandExecuted { ) -> CommandExecuted {
if let LapceCommand::ModalClose = command { if let LapceCommand::ModalClose = command {
self.shown = false; ctx.submit_command(Command::new(
LAPCE_UI_COMMAND,
LapceUICommand::Hide,
Target::Widget(self.panel_widget_id),
));
CommandExecuted::Yes CommandExecuted::Yes
} else { } else {
CommandExecuted::No CommandExecuted::No

View File

@ -143,6 +143,7 @@ fn event(
} }
keys.push(keypress); keys.push(keypress);
ctx.request_paint(); ctx.request_paint();
ctx.set_handled();
} }
} else { } else {
let mut keypress = data.keypress.clone(); let mut keypress = data.keypress.clone();

View File

@ -13,7 +13,10 @@
use inflector::Inflector; use inflector::Inflector;
use lapce_data::{ use lapce_data::{
buffer::{Buffer, BufferContent}, buffer::{Buffer, BufferContent},
command::{CommandExecuted, LapceCommand, LapceUICommand, LAPCE_UI_COMMAND}, command::{
CommandExecuted, LapceCommand, LapceUICommand, LAPCE_NEW_COMMAND,
LAPCE_UI_COMMAND,
},
config::{EditorConfig, LapceConfig, LapceTheme}, config::{EditorConfig, LapceConfig, LapceTheme},
data::{LapceEditorData, LapceTabData}, data::{LapceEditorData, LapceTabData},
keypress::KeyPressFocus, keypress::KeyPressFocus,
@ -114,6 +117,7 @@ fn mouse_down(
} }
ctx.set_handled(); ctx.set_handled();
ctx.request_focus();
if self.switcher_rect.contains(mouse_event.pos) { if self.switcher_rect.contains(mouse_event.pos) {
let index = ((mouse_event.pos.y - self.switcher_rect.y0) let index = ((mouse_event.pos.y - self.switcher_rect.y0)
/ self.switcher_line_height) / self.switcher_line_height)
@ -145,7 +149,16 @@ fn event(
if !data.settings.shown { if !data.settings.shown {
return; return;
} }
self.children[self.active].event(ctx, event, data, env); match event {
Event::Command(cmd) if cmd.is(LAPCE_UI_COMMAND) => {}
Event::Command(cmd) if cmd.is(LAPCE_NEW_COMMAND) => {}
_ => {
self.children[self.active].event(ctx, event, data, env);
}
}
if ctx.is_handled() {
return;
}
match event { match event {
Event::KeyDown(key_event) => { Event::KeyDown(key_event) => {
let mut keypress = data.keypress.clone(); let mut keypress = data.keypress.clone();
@ -181,11 +194,23 @@ fn event(
let command = cmd.get_unchecked(LAPCE_UI_COMMAND); let command = cmd.get_unchecked(LAPCE_UI_COMMAND);
match command { match command {
LapceUICommand::ShowSettings => { LapceUICommand::ShowSettings => {
ctx.request_focus();
self.active = 0; self.active = 0;
} }
LapceUICommand::ShowKeybindings => { LapceUICommand::ShowKeybindings => {
ctx.request_focus();
self.active = 2; self.active = 2;
} }
LapceUICommand::Hide => {
Arc::make_mut(&mut data.settings).shown = false;
if let Some(active) = *data.main_split.active {
ctx.submit_command(Command::new(
LAPCE_UI_COMMAND,
LapceUICommand::Focus,
Target::Widget(active),
));
}
}
_ => (), _ => (),
} }
} }