T44d Web · Hidden demos keep still, wide ones scroll whole, pastes read the web's clipboard
This commit is contained in:
26 files changed
+211
-101
No files matched your search
@@ -161,6 +161,8 @@ impl CodeEditor {
|
||||
div()
|
||||
.w(advance * digits as f32)
|
||||
.text_right()
|
||||
// Snapped to device pixels, the box can run short.
|
||||
.whitespace_nowrap()
|
||||
.when(current, |number| number.text_color(colors.fg))
|
||||
.child(number),
|
||||
)
|
||||
|
||||
+1
-1
@@ -97,7 +97,7 @@ pub(crate) fn bind_keys(cx: &mut App) {
|
||||
KeyBinding::new("secondary-alt-[", Fold, context),
|
||||
KeyBinding::new("secondary-alt-]", Unfold, context),
|
||||
];
|
||||
// The browser's paste event carries the clipboard to the input handler.
|
||||
// The browser's paste event reaches the input handler.
|
||||
if !cfg!(target_family = "wasm") {
|
||||
bindings.push(KeyBinding::new("secondary-v", Paste, context));
|
||||
}
|
||||
|
||||
+9
-2
@@ -112,6 +112,8 @@ pub struct CodeEditor {
|
||||
pub(crate) metrics: Metrics,
|
||||
pub(crate) dragging: bool,
|
||||
pub(crate) caret_on: bool,
|
||||
/// Blink runs only while focused, or unseen cursors redraw forever.
|
||||
focused: bool,
|
||||
pub(crate) chat_field: gpui::Entity<TextInput>,
|
||||
pub(crate) frame: Frame,
|
||||
blink_epoch: u64,
|
||||
@@ -133,8 +135,12 @@ impl CodeEditor {
|
||||
let chat_field =
|
||||
cx.new(|cx| TextInput::new(window, cx).placeholder("Ask to change this code"));
|
||||
let subscriptions = vec![
|
||||
cx.on_focus(&focus, window, |editor, _, cx| editor.restart_blink(cx)),
|
||||
cx.on_focus(&focus, window, |editor, _, cx| {
|
||||
editor.focused = true;
|
||||
editor.restart_blink(cx);
|
||||
}),
|
||||
cx.on_blur(&focus, window, |editor, _, cx| {
|
||||
editor.focused = false;
|
||||
editor.dragging = false;
|
||||
editor._blink = None;
|
||||
cx.notify();
|
||||
@@ -178,6 +184,7 @@ impl CodeEditor {
|
||||
metrics: Metrics::default(),
|
||||
dragging: false,
|
||||
caret_on: true,
|
||||
focused: false,
|
||||
chat_field,
|
||||
frame: Frame::default(),
|
||||
blink_epoch: 0,
|
||||
@@ -462,7 +469,7 @@ impl CodeEditor {
|
||||
self.blink_epoch += 1;
|
||||
let epoch = self.blink_epoch;
|
||||
let still = cx.theme().reduced_motion;
|
||||
self._blink = (!still).then(|| {
|
||||
self._blink = (!still && self.focused).then(|| {
|
||||
cx.spawn(async move |editor, cx| {
|
||||
loop {
|
||||
cx.background_executor().timer(BLINK).await;
|
||||
|
||||
+28
-1
@@ -1,4 +1,4 @@
|
||||
use std::time::Duration;
|
||||
use std::{cell::Cell, rc::Rc, time::Duration};
|
||||
|
||||
use gpui::{
|
||||
ClipboardItem, Entity, EntityInputHandler, KeyUpEvent, Keystroke, TestAppContext,
|
||||
@@ -256,3 +256,30 @@ fn a_browser_paste_gives_each_cursor_its_line(cx: &mut TestAppContext) {
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn only_a_focused_editor_blinks(cx: &mut TestAppContext) {
|
||||
let (editor, cx) = editor("a\nb", cx);
|
||||
let redraws = Rc::new(Cell::new(0));
|
||||
let counted = redraws.clone();
|
||||
let _count = cx.update(|_, cx| cx.observe(&editor, move |_, _| counted.set(counted.get() + 1)));
|
||||
editor.update(cx, |editor, cx| {
|
||||
let second = 2..2;
|
||||
editor.select([second], cx);
|
||||
});
|
||||
cx.run_until_parked();
|
||||
redraws.set(0);
|
||||
cx.executor().advance_clock(Duration::from_secs(3));
|
||||
cx.run_until_parked();
|
||||
assert_eq!(redraws.get(), 0, "an unfocused editor keeps still");
|
||||
cx.update(|window, cx| {
|
||||
window.activate_window();
|
||||
let focus = editor.read(cx).focus.clone();
|
||||
focus.focus(window, cx);
|
||||
});
|
||||
cx.run_until_parked();
|
||||
redraws.set(0);
|
||||
cx.executor().advance_clock(Duration::from_secs(3));
|
||||
cx.run_until_parked();
|
||||
assert!(redraws.get() > 2, "a focused one blinks");
|
||||
}
|
||||
Reference in new issue
Block a user