Gray formula placeholder, re-roll sample on clear

This commit is contained in:
John Preston
2026-06-26 16:13:56 +04:00
parent 1743eb071e
commit e9caa13c9a
2 changed files with 19 additions and 7 deletions
@@ -1669,23 +1669,31 @@ void EditMathBox(
host->resize(cardWidth, desiredHeight);
}, host->lifetime());
preview->setSource(startSource);
const auto interacted = box->lifetime().make_state<bool>(false);
if (startSource.isEmpty()) {
const auto applyRandomSample = [=] {
const auto &sample = kFormulaSamples[
base::RandomIndex(int(kFormulaSamples.size()))];
source->setPlaceholder(rpl::single(sample));
preview->setColor(st::windowSubTextFg);
preview->setSource(sample);
};
const auto wasEmpty = box->lifetime().make_state<bool>(
startSource.isEmpty());
if (startSource.isEmpty()) {
applyRandomSample();
}
source->changes(
) | rpl::on_next([=] {
if (!*interacted) {
*interacted = true;
const auto text = source->getLastText();
if (text.isEmpty()) {
if (!*wasEmpty) {
*wasEmpty = true;
applyRandomSample();
}
} else {
*wasEmpty = false;
preview->setColor(st::ivFormulaPreviewFg);
source->setPlaceholder(
tr::lng_formatting_math_source_placeholder());
preview->setSource(text);
}
preview->setSource(source->getLastText());
}, source->lifetime());
box->setTitle(editingExisting
+4
View File
@@ -577,9 +577,13 @@ ivFormulaPreviewRadius: 8px;
ivFormulaPreviewBg: windowBgOver;
ivFormulaPreviewFg: windowFg;
ivFormulaSourceField: InputField(defaultInputField) {
textMargins: margins(0px, 6px, 0px, 4px);
placeholderFg: placeholderFg;
placeholderFgActive: placeholderFgActive;
placeholderScale: 0.;
placeholderFont: normalFont;
placeholderShift: -50px;
heightMin: 33px;
}
defaultMarkdownTable: MarkdownTable {
cellPadding: margins(8px, 10px, 8px, 10px);