mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:47:34 +00:00
TextEditor: Show total character and word count without selection
This commit is contained in:
parent
46043b71cb
commit
4540c1ffab
2 changed files with 9 additions and 3 deletions
|
@ -809,13 +809,18 @@ void MainWidget::update_statusbar()
|
||||||
{
|
{
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
builder.appendff("Line: {}, Column: {}", m_editor->cursor().line() + 1, m_editor->cursor().column());
|
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()) {
|
if (m_editor->has_selection()) {
|
||||||
String selected_text = m_editor->selected_text();
|
String selected_text = m_editor->selected_text();
|
||||||
auto word_count = m_editor->number_of_selected_words();
|
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());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,5 +110,6 @@
|
||||||
|
|
||||||
@GUI::Statusbar {
|
@GUI::Statusbar {
|
||||||
name: "statusbar"
|
name: "statusbar"
|
||||||
|
label_count: 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue