diff options
author | Moustafa Raafat <MoustafaRaafat2@gmail.com> | 2022-04-23 17:36:26 +0200 |
---|---|---|
committer | Brian Gianforcaro <b.gianfo@gmail.com> | 2022-04-23 17:04:39 -0700 |
commit | 7b23dfea79858b976465f97ae8bd8ff71ec40fe1 (patch) | |
tree | 0cd51f27bf78372bd05bb5a26b9fab3291a4421d /Userland/Libraries | |
parent | e5022d866ec46cd1520fb3b83cdfe791db868fba (diff) | |
download | serenity-7b23dfea79858b976465f97ae8bd8ff71ec40fe1.zip |
LibGUI: Remove unused functions in EditingEngine class
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibGUI/EditingEngine.cpp | 254 | ||||
-rw-r--r-- | Userland/Libraries/LibGUI/EditingEngine.h | 8 |
2 files changed, 0 insertions, 262 deletions
diff --git a/Userland/Libraries/LibGUI/EditingEngine.cpp b/Userland/Libraries/LibGUI/EditingEngine.cpp index 34f6f56e69..46d43eb90c 100644 --- a/Userland/Libraries/LibGUI/EditingEngine.cpp +++ b/Userland/Libraries/LibGUI/EditingEngine.cpp @@ -11,16 +11,6 @@ namespace GUI { -constexpr bool is_vim_alphanumeric(u32 code_point) -{ - return is_ascii_alphanumeric(code_point) || code_point == '_'; -} - -constexpr bool is_vim_punctuation(u32 code_point) -{ - return is_ascii_punctuation(code_point) && code_point != '_'; -} - void EditingEngine::attach(TextEditor& editor) { VERIFY(!m_editor); @@ -378,250 +368,6 @@ void EditingEngine::get_selection_line_boundaries(size_t& first_line, size_t& la last_line -= 1; } -TextPosition EditingEngine::find_beginning_of_next_word() -{ - /* The rules that have been coded in: - * Jump to the next punct or alnum after any whitespace - * Jump to the next non-consecutive punct regardless of whitespace - * Jump to the next alnum if started on punct regardless of whitespace - * If the end of the input is reached, jump there - */ - - bool started_on_punct = is_vim_punctuation(m_editor->current_line().to_utf8().characters()[m_editor->cursor().column()]); - bool has_seen_whitespace = false; - bool is_first_line = true; - auto& lines = m_editor->lines(); - auto cursor = m_editor->cursor(); - for (size_t line_index = cursor.line(); line_index < lines.size(); line_index++) { - auto& line = lines.at(line_index); - - if (line.is_empty() && !is_first_line) { - return { line_index, 0 }; - } else if (line.is_empty()) { - has_seen_whitespace = true; - } - - is_first_line = false; - - for (size_t column_index = 0; column_index < lines.at(line_index).length(); column_index++) { - if (line_index == cursor.line() && column_index < cursor.column()) - continue; - u32 const* line_chars = line.view().code_points(); - const u32 current_char = line_chars[column_index]; - - if (started_on_punct && is_vim_alphanumeric(current_char)) { - return { line_index, column_index }; - } - - if (is_vim_punctuation(current_char) && !started_on_punct) { - return { line_index, column_index }; - } - - if (is_ascii_space(current_char)) - has_seen_whitespace = true; - - if (has_seen_whitespace && (is_vim_alphanumeric(current_char) || is_vim_punctuation(current_char))) { - return { line_index, column_index }; - } - - if (line_index == lines.size() - 1 && column_index == line.length() - 1) { - return { line_index, column_index }; - } - - // Implicit newline - if (column_index == line.length() - 1) - has_seen_whitespace = true; - } - } - VERIFY_NOT_REACHED(); -} - -void EditingEngine::move_to_beginning_of_next_word() -{ - m_editor->set_cursor(find_beginning_of_next_word()); -} - -TextPosition EditingEngine::find_end_of_next_word() -{ - /* The rules that have been coded in: - * If the current_char is alnum and the next is whitespace or punct - * If the current_char is punct and the next is whitespace or alnum - * If the end of the input is reached, jump there - */ - - bool is_first_line = true; - bool is_first_iteration = true; - auto& lines = m_editor->lines(); - auto cursor = m_editor->cursor(); - - if ((lines.at(cursor.line()).length() - cursor.column()) <= 1) - return { cursor.line(), cursor.column() }; - - for (size_t line_index = cursor.line(); line_index < lines.size(); line_index++) { - auto& line = lines.at(line_index); - - if (line.is_empty() && !is_first_line) { - return { line_index, 0 }; - } - - is_first_line = false; - - for (size_t column_index = 0; column_index < lines.at(line_index).length(); column_index++) { - if (line_index == cursor.line() && column_index < cursor.column()) - continue; - - u32 const* line_chars = line.view().code_points(); - const u32 current_char = line_chars[column_index]; - - if (column_index == lines.at(line_index).length() - 1 && !is_first_iteration && (is_vim_alphanumeric(current_char) || is_vim_punctuation(current_char))) - return { line_index, column_index }; - else if (column_index == lines.at(line_index).length() - 1) { - is_first_iteration = false; - continue; - } - - const u32 next_char = line_chars[column_index + 1]; - - if (!is_first_iteration && is_vim_alphanumeric(current_char) && (is_ascii_space(next_char) || is_vim_punctuation(next_char))) - return { line_index, column_index }; - - if (!is_first_iteration && is_vim_punctuation(current_char) && (is_ascii_space(next_char) || is_vim_alphanumeric(next_char))) - return { line_index, column_index }; - - if (line_index == lines.size() - 1 && column_index == line.length() - 1) { - return { line_index, column_index }; - } - - is_first_iteration = false; - } - } - VERIFY_NOT_REACHED(); -} - -void EditingEngine::move_to_end_of_next_word() -{ - m_editor->set_cursor(find_end_of_next_word()); -} - -TextPosition EditingEngine::find_end_of_previous_word() -{ - bool started_on_punct = is_vim_punctuation(m_editor->current_line().to_utf8().characters()[m_editor->cursor().column()]); - bool is_first_line = true; - bool has_seen_whitespace = false; - auto& lines = m_editor->lines(); - auto cursor = m_editor->cursor(); - for (size_t line_index = cursor.line(); (int)line_index >= 0; line_index--) { - auto& line = lines.at(line_index); - - if (line.is_empty() && !is_first_line) { - return { line_index, 0 }; - } else if (line.is_empty()) { - has_seen_whitespace = true; - } - - is_first_line = false; - - size_t line_length = lines.at(line_index).length(); - for (size_t column_index = line_length - 1; (int)column_index >= 0; column_index--) { - if (line_index == cursor.line() && column_index > cursor.column()) - continue; - - u32 const* line_chars = line.view().code_points(); - const u32 current_char = line_chars[column_index]; - - if (started_on_punct && is_vim_alphanumeric(current_char)) { - return { line_index, column_index }; - } - - if (is_vim_punctuation(current_char) && !started_on_punct) { - return { line_index, column_index }; - } - - if (is_ascii_space(current_char)) { - has_seen_whitespace = true; - } - - if (has_seen_whitespace && (is_vim_alphanumeric(current_char) || is_vim_punctuation(current_char))) { - return { line_index, column_index }; - } - - if (line_index == 0 && column_index == 0) { - return { line_index, column_index }; - } - - // Implicit newline when wrapping back up to the end of the previous line. - if (column_index == 0) - has_seen_whitespace = true; - } - } - VERIFY_NOT_REACHED(); -} - -void EditingEngine::move_to_end_of_previous_word() -{ - m_editor->set_cursor(find_end_of_previous_word()); -} - -TextPosition EditingEngine::find_beginning_of_previous_word() -{ - bool is_first_iterated_line = true; - bool is_first_iteration = true; - auto& lines = m_editor->lines(); - auto cursor = m_editor->cursor(); - - if ((lines.at(cursor.line()).length() - cursor.column()) <= 1) - return { cursor.line(), cursor.column() }; - - for (size_t line_index = cursor.line(); (int)line_index >= 0; line_index--) { - auto& line = lines.at(line_index); - - if (line.is_empty() && !is_first_iterated_line) { - return { line_index, 0 }; - } - - is_first_iterated_line = false; - - size_t line_length = lines.at(line_index).length(); - for (size_t column_index = line_length; (int)column_index >= 0; column_index--) { - if (line_index == cursor.line() && column_index > cursor.column()) - continue; - - if (column_index == line_length) { - is_first_iteration = false; - continue; - } - - u32 const* line_chars = line.view().code_points(); - const u32 current_char = line_chars[column_index]; - - if (column_index == 0 && !is_first_iteration && (is_vim_alphanumeric(current_char) || is_vim_punctuation(current_char))) { - return { line_index, column_index }; - } else if (line_index == 0 && column_index == 0) { - return { line_index, column_index }; - } else if (column_index == 0 && is_first_iteration) { - is_first_iteration = false; - continue; - } - - const u32 next_char = line_chars[column_index - 1]; - - if (!is_first_iteration && is_vim_alphanumeric(current_char) && (is_ascii_space(next_char) || is_vim_punctuation(next_char))) - return { line_index, column_index }; - - if (!is_first_iteration && is_vim_punctuation(current_char) && (is_ascii_space(next_char) || is_vim_alphanumeric(next_char))) - return { line_index, column_index }; - - is_first_iteration = false; - } - } - VERIFY_NOT_REACHED(); -} - -void EditingEngine::move_to_beginning_of_previous_word() -{ - m_editor->set_cursor(find_beginning_of_previous_word()); -} - void EditingEngine::move_selected_lines_up() { if (!m_editor->is_editable()) diff --git a/Userland/Libraries/LibGUI/EditingEngine.h b/Userland/Libraries/LibGUI/EditingEngine.h index bef68b2200..e3692feb03 100644 --- a/Userland/Libraries/LibGUI/EditingEngine.h +++ b/Userland/Libraries/LibGUI/EditingEngine.h @@ -64,14 +64,6 @@ protected: void move_page_down(); void move_to_first_line(); void move_to_last_line(); - TextPosition find_beginning_of_next_word(); - void move_to_beginning_of_next_word(); - TextPosition find_end_of_next_word(); - void move_to_end_of_next_word(); - TextPosition find_end_of_previous_word(); - void move_to_end_of_previous_word(); - TextPosition find_beginning_of_previous_word(); - void move_to_beginning_of_previous_word(); void move_up(double page_height_factor); void move_down(double page_height_factor); |