Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/gui/note_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1146,11 +1146,13 @@ impl NotePanel {
// window closure (save, open externally, etc.). Don't capture borrows of `self.note.slug` in
// the closure environment - keep IDs based on an owned clone instead.
let slug = self.note.slug.clone();
let window_id = egui::Id::new(("note_panel_window", self.note.slug.clone()));
let content_id = egui::Id::new(("note_content", slug.clone()));
let scroll_id_source = ("note_scroll", slug.clone());
let text_id_source = ("note_text", slug);

egui::Window::new(self.note.title.clone())
.id(window_id)
.open(&mut open)
.resizable(true)
.default_size(app.note_panel_default_size)
Expand Down Expand Up @@ -3878,6 +3880,43 @@ mod tests {
});
}

#[test]
fn markdown_title_change_keeps_note_window_rect() {
let ctx = egui::Context::default();
let mut app = new_app(&ctx);
app.note_panel_default_size = (420.0, 320.0);

let mut panel = NotePanel::from_note(note_with_slug("Original Title", "stable-note"));
let window_id = egui::Id::new(("note_panel_window", panel.note.slug.clone()));
let raw_input = || egui::RawInput {
screen_rect: Some(egui::Rect::from_min_size(
egui::Pos2::ZERO,
egui::vec2(1200.0, 900.0),
)),
..Default::default()
};

let _ = ctx.run(raw_input(), |ctx| {
panel.ui(ctx, &mut app);
});
let original_rect = ctx
.memory(|memory| memory.area_rect(window_id))
.expect("note window rect should be remembered after rendering");

panel.note.title = "Renamed From Markdown".into();
panel.note.content = "# Renamed From Markdown\n\nBody".into();
app.note_panel_default_size = (760.0, 560.0);

let _ = ctx.run(raw_input(), |ctx| {
panel.ui(ctx, &mut app);
});
let renamed_rect = ctx
.memory(|memory| memory.area_rect(window_id))
.expect("note window rect should still be remembered after title changes");

assert_eq!(renamed_rect, original_rect);
}

#[test]
fn edit_mode_editor_height_tracks_tall_content_pane() {
let ctx = egui::Context::default();
Expand Down
8 changes: 7 additions & 1 deletion tests/focus_visibility.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use eframe::egui;
use multi_launcher::hotkey::{Hotkey, HotkeyTrigger};
use multi_launcher::visibility::handle_visibility_trigger;
use multi_launcher::window_manager::{
MOCK_MOUSE_LOCK, clear_mock_mouse_position, set_mock_mouse_position,
};
use std::sync::{
atomic::{AtomicBool, Ordering},
Arc, Mutex,
atomic::{AtomicBool, Ordering},
};

#[path = "mock_ctx.rs"]
Expand All @@ -12,6 +15,8 @@ use mock_ctx::MockCtx;

#[test]
fn focus_when_becoming_visible() {
let _mouse_lock = MOCK_MOUSE_LOCK.lock().unwrap();
set_mock_mouse_position(Some((200.0, 110.0)));
let trigger = HotkeyTrigger::new(Hotkey::default());
let visibility = Arc::new(AtomicBool::new(false));
let restore = Arc::new(AtomicBool::new(false));
Expand Down Expand Up @@ -39,6 +44,7 @@ fn focus_when_becoming_visible() {

assert_eq!(visibility.load(Ordering::SeqCst), true);
assert!(queued_visibility.is_none());
clear_mock_mouse_position();

let cmds = ctx.commands.lock().unwrap();
assert_eq!(cmds.len(), 4);
Expand Down
8 changes: 7 additions & 1 deletion tests/gui_visibility.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use eframe::egui;
use multi_launcher::hotkey::{Hotkey, HotkeyTrigger};
use multi_launcher::visibility::handle_visibility_trigger;
use multi_launcher::window_manager::{
MOCK_MOUSE_LOCK, clear_mock_mouse_position, set_mock_mouse_position,
};
use std::sync::{
atomic::{AtomicBool, Ordering},
Arc, Mutex,
atomic::{AtomicBool, Ordering},
};

#[path = "mock_ctx.rs"]
Expand All @@ -12,6 +15,8 @@ use mock_ctx::MockCtx;

#[test]
fn queued_visibility_applies_when_context_available() {
let _mouse_lock = MOCK_MOUSE_LOCK.lock().unwrap();
set_mock_mouse_position(Some((200.0, 110.0)));
let trigger = HotkeyTrigger::new(Hotkey::default());
let visibility = Arc::new(AtomicBool::new(false));
let restore = Arc::new(AtomicBool::new(false));
Expand Down Expand Up @@ -61,6 +66,7 @@ fn queued_visibility_applies_when_context_available() {
assert!(!changed);

assert!(queued_visibility.is_none());
clear_mock_mouse_position();
let cmds = ctx.commands.lock().unwrap();
assert_eq!(cmds.len(), 4);
match cmds[0] {
Expand Down
2 changes: 1 addition & 1 deletion tests/note_panel_scroll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ fn note_panel_max_height_tracks_available_screen_height() {
let _ = ctx.end_frame();

let rect = ctx
.memory(|m| m.area_rect(egui::Id::new("Long note")))
.memory(|m| m.area_rect(egui::Id::new(("note_panel_window", String::new()))))
.expect("window rect");
assert!(
rect.height() > 600.0,
Expand Down
8 changes: 7 additions & 1 deletion tests/trigger_visibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ use multi_launcher::hotkey::{Hotkey, HotkeyTrigger};
use multi_launcher::plugin::PluginManager;
use multi_launcher::settings::Settings;
use multi_launcher::visibility::handle_visibility_trigger;
use multi_launcher::window_manager::{
MOCK_MOUSE_LOCK, clear_mock_mouse_position, set_mock_mouse_position,
};
use multi_launcher::{gui::ActivationSource, gui::LauncherApp};
use std::sync::{
atomic::{AtomicBool, Ordering},
Arc, Mutex,
atomic::{AtomicBool, Ordering},
};

#[path = "mock_ctx.rs"]
Expand Down Expand Up @@ -35,6 +38,8 @@ fn new_app(ctx: &egui::Context) -> LauncherApp {

#[test]
fn visibility_toggle_immediate_when_context_present() {
let _mouse_lock = MOCK_MOUSE_LOCK.lock().unwrap();
set_mock_mouse_position(Some((200.0, 110.0)));
let trigger = HotkeyTrigger::new(Hotkey::default());
let visibility = Arc::new(AtomicBool::new(false));
let restore = Arc::new(AtomicBool::new(false));
Expand Down Expand Up @@ -62,6 +67,7 @@ fn visibility_toggle_immediate_when_context_present() {

assert_eq!(visibility.load(Ordering::SeqCst), true);
assert!(queued_visibility.is_none());
clear_mock_mouse_position();

let cmds = ctx.commands.lock().unwrap();
assert_eq!(cmds.len(), 4);
Expand Down
20 changes: 14 additions & 6 deletions tests/windows_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@ use multi_launcher::plugins::windows::WindowsPlugin;
fn search_lists_windows() {
let plugin = WindowsPlugin;
let results = plugin.search("win");
assert!(results
.iter()
.any(|a| a.action.starts_with("window:switch:")));
assert!(results
.iter()
.any(|a| a.action.starts_with("window:close:")));
if results.is_empty() {
assert_eq!(plugin.commands()[0].action, "query:win ");
return;
}
assert!(
results
.iter()
.any(|a| a.action.starts_with("window:switch:"))
);
assert!(
results
.iter()
.any(|a| a.action.starts_with("window:close:"))
);
}