input: Update Input text method to return &SharedString type. (#800)

## Break Changes

- input: Now the `text` method `Input` changed return type from
`SharedString` to `&SharedString`.
- list: Remove `set_query` and `query` method from `List`, you can use
`query_input` to instead.
This commit is contained in:
Jason Lee 2025-04-17 19:52:14 +08:00 committed by GitHub
parent bef1dd2544
commit 413d156ef4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 5 additions and 19 deletions

View file

@ -82,7 +82,7 @@ impl WebViewStory {
input input
}); });
let url = address_input.read(cx).text(); let url = address_input.read(cx).text().clone();
webview.update(cx, |view, _| { webview.update(cx, |view, _| {
view.load_url(&url); view.load_url(&url);
}); });
@ -98,7 +98,7 @@ impl WebViewStory {
&address_input, &address_input,
|this: &mut Self, input, event: &InputEvent, cx| match event { |this: &mut Self, input, event: &InputEvent, cx| match event {
InputEvent::PressEnter { .. } => { InputEvent::PressEnter { .. } => {
let url = input.read(cx).text(); let url = input.read(cx).text().clone();
this.webview.update(cx, |view, _| { this.webview.update(cx, |view, _| {
view.load_url(&url); view.load_url(&url);
}); });

View file

@ -699,8 +699,8 @@ impl TextInput {
} }
/// Return the text of the input field. /// Return the text of the input field.
pub fn text(&self) -> SharedString { pub fn text(&self) -> &SharedString {
self.text.clone() &self.text
} }
pub fn disabled(&self) -> bool { pub fn disabled(&self) -> bool {

View file

@ -11,8 +11,7 @@ use crate::{
use gpui::{ use gpui::{
div, prelude::FluentBuilder, uniform_list, AnyElement, AppContext, Entity, FocusHandle, div, prelude::FluentBuilder, uniform_list, AnyElement, AppContext, Entity, FocusHandle,
Focusable, InteractiveElement, IntoElement, KeyBinding, Length, ListSizingBehavior, Focusable, InteractiveElement, IntoElement, KeyBinding, Length, ListSizingBehavior,
MouseButton, ParentElement, Render, SharedString, Styled, Task, UniformListScrollHandle, MouseButton, ParentElement, Render, Styled, Task, UniformListScrollHandle, Window,
Window,
}; };
use gpui::{px, App, Context, EventEmitter, MouseDownEvent, ScrollStrategy, Subscription}; use gpui::{px, App, Context, EventEmitter, MouseDownEvent, ScrollStrategy, Subscription};
use rust_i18n::t; use rust_i18n::t;
@ -278,19 +277,6 @@ where
self.selected_index self.selected_index
} }
/// Set the query_input text
pub fn set_query(&mut self, query: &str, window: &mut Window, cx: &mut Context<Self>) {
if let Some(query_input) = &self.query_input {
let query = query.to_owned();
query_input.update(cx, |input, cx| input.set_text(query, window, cx))
}
}
/// Get the query_input text
pub fn query(&self, _: &mut Window, cx: &mut Context<Self>) -> Option<SharedString> {
self.query_input.as_ref().map(|input| input.read(cx).text())
}
fn render_scrollbar(&self, _: &mut Window, cx: &mut Context<Self>) -> Option<impl IntoElement> { fn render_scrollbar(&self, _: &mut Window, cx: &mut Context<Self>) -> Option<impl IntoElement> {
if !self.scrollbar_visible { if !self.scrollbar_visible {
return None; return None;