mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-24 11:01:54 +00:00
Merge pull request #2075 from zed-industries/add-upper-character-count-limit
Add upper character count limit
This commit is contained in:
commit
a66a0cfd70
1 changed files with 21 additions and 16 deletions
|
@ -1,4 +1,7 @@
|
||||||
use std::{ops::Range, sync::Arc};
|
use std::{
|
||||||
|
ops::{Range, RangeInclusive},
|
||||||
|
sync::Arc,
|
||||||
|
};
|
||||||
|
|
||||||
use anyhow::bail;
|
use anyhow::bail;
|
||||||
use client::{Client, ZED_SECRET_CLIENT_TOKEN};
|
use client::{Client, ZED_SECRET_CLIENT_TOKEN};
|
||||||
|
@ -32,11 +35,7 @@ lazy_static! {
|
||||||
std::env::var("ZED_SERVER_URL").unwrap_or_else(|_| "https://zed.dev".to_string());
|
std::env::var("ZED_SERVER_URL").unwrap_or_else(|_| "https://zed.dev".to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
const FEEDBACK_CHAR_COUNT_RANGE: Range<usize> = Range {
|
const FEEDBACK_CHAR_LIMIT: RangeInclusive<usize> = 10..=5000;
|
||||||
start: 10,
|
|
||||||
end: 1000,
|
|
||||||
};
|
|
||||||
|
|
||||||
const FEEDBACK_PLACEHOLDER_TEXT: &str = "Thanks for spending time with Zed. Enter your feedback here as Markdown. Save the tab to submit your feedback.";
|
const FEEDBACK_PLACEHOLDER_TEXT: &str = "Thanks for spending time with Zed. Enter your feedback here as Markdown. Save the tab to submit your feedback.";
|
||||||
const FEEDBACK_SUBMISSION_ERROR_TEXT: &str =
|
const FEEDBACK_SUBMISSION_ERROR_TEXT: &str =
|
||||||
"Feedback failed to submit, see error log for details.";
|
"Feedback failed to submit, see error log for details.";
|
||||||
|
@ -139,18 +138,24 @@ impl FeedbackEditor {
|
||||||
_: gpui::ModelHandle<Project>,
|
_: gpui::ModelHandle<Project>,
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) -> Task<anyhow::Result<()>> {
|
) -> Task<anyhow::Result<()>> {
|
||||||
let feedback_text_length = self.editor.read(cx).buffer().read(cx).len(cx);
|
let feedback_char_count = self.editor.read(cx).buffer().read(cx).len(cx);
|
||||||
|
|
||||||
if feedback_text_length <= FEEDBACK_CHAR_COUNT_RANGE.start {
|
let error = if feedback_char_count < *FEEDBACK_CHAR_LIMIT.start() {
|
||||||
cx.prompt(
|
Some(format!(
|
||||||
PromptLevel::Critical,
|
"Feedback can't be shorter than {} characters.",
|
||||||
&format!(
|
FEEDBACK_CHAR_LIMIT.start()
|
||||||
"Feedback must be longer than {} characters",
|
))
|
||||||
FEEDBACK_CHAR_COUNT_RANGE.start
|
} else if feedback_char_count > *FEEDBACK_CHAR_LIMIT.end() {
|
||||||
),
|
Some(format!(
|
||||||
&["OK"],
|
"Feedback can't be longer than {} characters.",
|
||||||
);
|
FEEDBACK_CHAR_LIMIT.end()
|
||||||
|
))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Some(error) = error {
|
||||||
|
cx.prompt(PromptLevel::Critical, &error, &["OK"]);
|
||||||
return Task::ready(Ok(()));
|
return Task::ready(Ok(()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue