T44d Web · Stories stand alone: nested ones surface, hidden ones drop their demos, early themes land, pastes arrive
This commit is contained in:
1 parent
edab58e91a
commit
2463bb0ac9
22 files changed
+352
-172
No files matched your search
+18
-2
@@ -7,8 +7,8 @@ mod tags;
|
||||
mod upload;
|
||||
|
||||
use gpui::{
|
||||
AppContext as _, Context, Entity, EntityInputHandler, IntoElement, KeyUpEvent, Keystroke,
|
||||
ParentElement, Render, TestAppContext, VisualTestContext, Window, div, px,
|
||||
AppContext as _, ClipboardItem, Context, Entity, EntityInputHandler, IntoElement, KeyUpEvent,
|
||||
Keystroke, ParentElement, Render, TestAppContext, VisualTestContext, Window, div, px,
|
||||
};
|
||||
|
||||
use super::{Input, MaskedInput, NumberInput, PinInput, TextInput, bind_keys};
|
||||
@@ -146,6 +146,22 @@ fn a_committed_composition_obeys_the_filter_and_length(cx: &mut TestAppContext)
|
||||
assert_eq!(text(field, cx), "");
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn a_browser_paste_undoes_apart_from_the_typing(cx: &mut TestAppContext) {
|
||||
let (fields, cx) = open(1, false, cx);
|
||||
let field = &fields[0];
|
||||
focus(field, cx);
|
||||
cx.simulate_input("ab");
|
||||
cx.update(|window, cx| {
|
||||
field.update(cx, |input, cx| {
|
||||
EntityInputHandler::paste(input, ClipboardItem::new_string("cd".into()), window, cx)
|
||||
})
|
||||
});
|
||||
assert_eq!(text(field, cx), "abcd");
|
||||
cx.simulate_keystrokes("cmd-z");
|
||||
assert_eq!(text(field, cx), "ab");
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn undo_leaves_a_disabled_field_alone(cx: &mut TestAppContext) {
|
||||
let (fields, cx) = open(1, false, cx);
|
||||
|
||||
@@ -82,7 +82,6 @@ pub(crate) fn bind_keys(cx: &mut App) {
|
||||
KeyBinding::new("secondary-a", SelectAll, Some(CONTEXT)),
|
||||
KeyBinding::new("secondary-c", Copy, Some(CONTEXT)),
|
||||
KeyBinding::new("secondary-x", Cut, Some(CONTEXT)),
|
||||
KeyBinding::new("secondary-v", Paste, Some(CONTEXT)),
|
||||
KeyBinding::new("secondary-z", Undo, Some(CONTEXT)),
|
||||
KeyBinding::new("secondary-shift-z", Redo, Some(CONTEXT)),
|
||||
KeyBinding::new("enter", Enter, Some(CONTEXT)),
|
||||
@@ -90,6 +89,10 @@ pub(crate) fn bind_keys(cx: &mut App) {
|
||||
KeyBinding::new("secondary-enter", Submit, Some(CONTEXT)),
|
||||
KeyBinding::new("secondary-enter", Submit, Some(FORM_CONTEXT)),
|
||||
];
|
||||
// The browser's paste event carries the clipboard to the input handler.
|
||||
if !cfg!(target_family = "wasm") {
|
||||
bindings.push(KeyBinding::new("secondary-v", Paste, Some(CONTEXT)));
|
||||
}
|
||||
if cfg!(target_os = "macos") {
|
||||
bindings.extend([
|
||||
KeyBinding::new("cmd-left", Home, Some(CONTEXT)),
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
use std::ops::Range;
|
||||
|
||||
use gpui::{Bounds, Context, EntityInputHandler, Pixels, Point, UTF16Selection, Window};
|
||||
use gpui::{
|
||||
Bounds, ClipboardItem, Context, EntityInputHandler, Pixels, Point, UTF16Selection, Window,
|
||||
};
|
||||
|
||||
use super::{
|
||||
TextInput,
|
||||
@@ -18,6 +20,12 @@ impl TextInput {
|
||||
}
|
||||
|
||||
impl EntityInputHandler for TextInput {
|
||||
fn paste(&mut self, item: ClipboardItem, _: &mut Window, cx: &mut Context<Self>) {
|
||||
if let Some(text) = item.text() {
|
||||
self.replace(self.selection.clone(), &text, false, cx);
|
||||
}
|
||||
}
|
||||
|
||||
fn text_for_range(
|
||||
&mut self,
|
||||
range_utf16: Range<usize>,
|
||||
|
||||
Reference in new issue
Block a user