mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-05 07:41:01 +00:00
LibGUI+TextEditor: Add the calculation of selected words
This moves the calculation of selected words that was originally in the TextEditor application to TextEditor in LibGUI. This allows all applications with text editors to get this number without having to calculating it themselves.
This commit is contained in:
parent
074813e441
commit
8146543a43
Notes:
sideshowbarker
2024-07-18 17:20:41 +09:00
Author: https://github.com/ry-sev
Commit: 8146543a43
Pull-request: https://github.com/SerenityOS/serenity/pull/7473
3 changed files with 25 additions and 13 deletions
|
@ -765,20 +765,8 @@ void MainWidget::update_statusbar()
|
|||
builder.appendff("Line: {}, Column: {}", m_editor->cursor().line() + 1, m_editor->cursor().column());
|
||||
|
||||
if (m_editor->has_selection()) {
|
||||
int word_count = 0;
|
||||
bool in_word = false;
|
||||
String selected_text = m_editor->selected_text();
|
||||
for (char c : selected_text) {
|
||||
if (in_word && isspace(c)) {
|
||||
in_word = false;
|
||||
word_count++;
|
||||
continue;
|
||||
}
|
||||
if (!in_word && !isspace(c))
|
||||
in_word = true;
|
||||
}
|
||||
if (in_word)
|
||||
word_count++;
|
||||
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");
|
||||
}
|
||||
m_statusbar->set_text(builder.to_string());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue