TextEditor: Show total character and word count without selection

This commit is contained in:
thankyouverycool 2021-09-18 16:30:23 -04:00 committed by Andreas Kling
parent 46043b71cb
commit 4540c1ffab
Notes: sideshowbarker 2024-07-18 03:41:52 +09:00
2 changed files with 9 additions and 3 deletions

View file

@ -809,13 +809,18 @@ void MainWidget::update_statusbar()
{
StringBuilder builder;
builder.appendff("Line: {}, Column: {}", m_editor->cursor().line() + 1, m_editor->cursor().column());
m_statusbar->set_text(0, builder.to_string());
builder.clear();
if (m_editor->has_selection()) {
String selected_text = m_editor->selected_text();
auto word_count = m_editor->number_of_selected_words();
builder.appendff(" Selected: {} {} ({} {})", selected_text.length(), selected_text.length() == 1 ? "character" : "characters", word_count, word_count != 1 ? "words" : "word");
builder.appendff("{} {} ({} {}) selected", selected_text.length(), selected_text.length() == 1 ? "character" : "characters", word_count, word_count != 1 ? "words" : "word");
} else {
String text = m_editor->text();
auto word_count = m_editor->number_of_words();
builder.appendff("{} {} ({} {})", text.length(), text.length() == 1 ? "character" : "characters", word_count, word_count != 1 ? "words" : "word");
}
m_statusbar->set_text(builder.to_string());
m_statusbar->set_text(1, builder.to_string());
}
}

View file

@ -110,5 +110,6 @@
@GUI::Statusbar {
name: "statusbar"
label_count: 2
}
}