mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 00:27:43 +00:00
AK: Use size_t for the length of strings
Using int was a mistake. This patch changes String, StringImpl, StringView and StringBuilder to use size_t instead of int for lengths. Obviously a lot of code needs to change as a result of this.
This commit is contained in:
parent
1726c17d0d
commit
6f4c380d95
54 changed files with 387 additions and 377 deletions
|
@ -22,17 +22,17 @@ void GTextDocument::set_text(const StringView& text)
|
|||
m_spans.clear();
|
||||
remove_all_lines();
|
||||
|
||||
int start_of_current_line = 0;
|
||||
size_t start_of_current_line = 0;
|
||||
|
||||
auto add_line = [&](int current_position) {
|
||||
int line_length = current_position - start_of_current_line;
|
||||
auto add_line = [&](size_t current_position) {
|
||||
size_t line_length = current_position - start_of_current_line;
|
||||
auto line = make<GTextDocumentLine>(*this);
|
||||
if (line_length)
|
||||
line->set_text(*this, text.substring_view(start_of_current_line, current_position - start_of_current_line));
|
||||
append_line(move(line));
|
||||
start_of_current_line = current_position + 1;
|
||||
};
|
||||
int i = 0;
|
||||
size_t i = 0;
|
||||
for (i = 0; i < text.length(); ++i) {
|
||||
if (text[i] == '\n')
|
||||
add_line(i);
|
||||
|
@ -44,10 +44,10 @@ void GTextDocument::set_text(const StringView& text)
|
|||
client->document_did_set_text();
|
||||
}
|
||||
|
||||
int GTextDocumentLine::first_non_whitespace_column() const
|
||||
size_t GTextDocumentLine::first_non_whitespace_column() const
|
||||
{
|
||||
for (int i = 0; i < length(); ++i) {
|
||||
if (!isspace(m_text[i]))
|
||||
for (size_t i = 0; i < length(); ++i) {
|
||||
if (!isspace(m_text[(int)i]))
|
||||
return i;
|
||||
}
|
||||
return length();
|
||||
|
@ -78,12 +78,12 @@ void GTextDocumentLine::set_text(GTextDocument& document, const StringView& text
|
|||
clear(document);
|
||||
return;
|
||||
}
|
||||
m_text.resize(text.length() + 1);
|
||||
m_text.resize((int)text.length() + 1);
|
||||
memcpy(m_text.data(), text.characters_without_null_termination(), text.length() + 1);
|
||||
document.update_views({});
|
||||
}
|
||||
|
||||
void GTextDocumentLine::append(GTextDocument& document, const char* characters, int length)
|
||||
void GTextDocumentLine::append(GTextDocument& document, const char* characters, size_t length)
|
||||
{
|
||||
int old_length = m_text.size() - 1;
|
||||
m_text.resize(m_text.size() + length);
|
||||
|
@ -102,31 +102,31 @@ void GTextDocumentLine::prepend(GTextDocument& document, char ch)
|
|||
insert(document, 0, ch);
|
||||
}
|
||||
|
||||
void GTextDocumentLine::insert(GTextDocument& document, int index, char ch)
|
||||
void GTextDocumentLine::insert(GTextDocument& document, size_t index, char ch)
|
||||
{
|
||||
if (index == length()) {
|
||||
m_text.last() = ch;
|
||||
m_text.append(0);
|
||||
} else {
|
||||
m_text.insert(index, move(ch));
|
||||
m_text.insert((int)index, move(ch));
|
||||
}
|
||||
document.update_views({});
|
||||
}
|
||||
|
||||
void GTextDocumentLine::remove(GTextDocument& document, int index)
|
||||
void GTextDocumentLine::remove(GTextDocument& document, size_t index)
|
||||
{
|
||||
if (index == length()) {
|
||||
m_text.take_last();
|
||||
m_text.last() = 0;
|
||||
} else {
|
||||
m_text.remove(index);
|
||||
m_text.remove((int)index);
|
||||
}
|
||||
document.update_views({});
|
||||
}
|
||||
|
||||
void GTextDocumentLine::truncate(GTextDocument& document, int length)
|
||||
void GTextDocumentLine::truncate(GTextDocument& document, size_t length)
|
||||
{
|
||||
m_text.resize(length + 1);
|
||||
m_text.resize((int)length + 1);
|
||||
m_text.last() = 0;
|
||||
document.update_views({});
|
||||
}
|
||||
|
@ -140,18 +140,18 @@ void GTextDocument::append_line(NonnullOwnPtr<GTextDocumentLine> line)
|
|||
}
|
||||
}
|
||||
|
||||
void GTextDocument::insert_line(int line_index, NonnullOwnPtr<GTextDocumentLine> line)
|
||||
void GTextDocument::insert_line(size_t line_index, NonnullOwnPtr<GTextDocumentLine> line)
|
||||
{
|
||||
lines().insert(line_index, move(line));
|
||||
lines().insert((int)line_index, move(line));
|
||||
if (m_client_notifications_enabled) {
|
||||
for (auto* client : m_clients)
|
||||
client->document_did_insert_line(line_index);
|
||||
}
|
||||
}
|
||||
|
||||
void GTextDocument::remove_line(int line_index)
|
||||
void GTextDocument::remove_line(size_t line_index)
|
||||
{
|
||||
lines().remove(line_index);
|
||||
lines().remove((int)line_index);
|
||||
if (m_client_notifications_enabled) {
|
||||
for (auto* client : m_clients)
|
||||
client->document_did_remove_line(line_index);
|
||||
|
@ -207,10 +207,10 @@ String GTextDocument::text_in_range(const GTextRange& a_range) const
|
|||
auto range = a_range.normalized();
|
||||
|
||||
StringBuilder builder;
|
||||
for (int i = range.start().line(); i <= range.end().line(); ++i) {
|
||||
auto& line = lines()[i];
|
||||
int selection_start_column_on_line = range.start().line() == i ? range.start().column() : 0;
|
||||
int selection_end_column_on_line = range.end().line() == i ? range.end().column() : line.length();
|
||||
for (size_t i = range.start().line(); i <= range.end().line(); ++i) {
|
||||
auto& line = this->line(i);
|
||||
size_t selection_start_column_on_line = range.start().line() == i ? range.start().column() : 0;
|
||||
size_t selection_end_column_on_line = range.end().line() == i ? range.end().column() : line.length();
|
||||
builder.append(line.characters() + selection_start_column_on_line, selection_end_column_on_line - selection_start_column_on_line);
|
||||
if (i != range.end().line())
|
||||
builder.append('\n');
|
||||
|
@ -222,7 +222,7 @@ String GTextDocument::text_in_range(const GTextRange& a_range) const
|
|||
char GTextDocument::character_at(const GTextPosition& position) const
|
||||
{
|
||||
ASSERT(position.line() < line_count());
|
||||
auto& line = lines()[position.line()];
|
||||
auto& line = this->line(position.line());
|
||||
if (position.column() == line.length())
|
||||
return '\n';
|
||||
return line.characters()[position.column()];
|
||||
|
@ -230,7 +230,7 @@ char GTextDocument::character_at(const GTextPosition& position) const
|
|||
|
||||
GTextPosition GTextDocument::next_position_after(const GTextPosition& position, SearchShouldWrap should_wrap) const
|
||||
{
|
||||
auto& line = lines()[position.line()];
|
||||
auto& line = this->line(position.line());
|
||||
if (position.column() == line.length()) {
|
||||
if (position.line() == line_count() - 1) {
|
||||
if (should_wrap == SearchShouldWrap::Yes)
|
||||
|
@ -247,12 +247,12 @@ GTextPosition GTextDocument::previous_position_before(const GTextPosition& posit
|
|||
if (position.column() == 0) {
|
||||
if (position.line() == 0) {
|
||||
if (should_wrap == SearchShouldWrap::Yes) {
|
||||
auto& last_line = lines()[line_count() - 1];
|
||||
auto& last_line = this->line(line_count() - 1);
|
||||
return { line_count() - 1, last_line.length() };
|
||||
}
|
||||
return {};
|
||||
}
|
||||
auto& prev_line = lines()[position.line() - 1];
|
||||
auto& prev_line = this->line(position.line() - 1);
|
||||
return { position.line() - 1, prev_line.length() };
|
||||
}
|
||||
return { position.line(), position.column() - 1 };
|
||||
|
@ -267,7 +267,7 @@ GTextRange GTextDocument::find_next(const StringView& needle, const GTextPositio
|
|||
GTextPosition original_position = position;
|
||||
|
||||
GTextPosition start_of_potential_match;
|
||||
int needle_index = 0;
|
||||
size_t needle_index = 0;
|
||||
|
||||
do {
|
||||
auto ch = character_at(position);
|
||||
|
@ -298,16 +298,16 @@ GTextRange GTextDocument::find_previous(const StringView& needle, const GTextPos
|
|||
GTextPosition original_position = position;
|
||||
|
||||
GTextPosition end_of_potential_match;
|
||||
int needle_index = needle.length() - 1;
|
||||
size_t needle_index = needle.length() - 1;
|
||||
|
||||
do {
|
||||
auto ch = character_at(position);
|
||||
if (ch == needle[needle_index]) {
|
||||
if (needle_index == needle.length() - 1)
|
||||
end_of_potential_match = position;
|
||||
--needle_index;
|
||||
if (needle_index < 0)
|
||||
if (needle_index == 0)
|
||||
return { position, next_position_after(end_of_potential_match, should_wrap) };
|
||||
--needle_index;
|
||||
} else {
|
||||
if (needle_index < needle.length() - 1)
|
||||
position = end_of_potential_match;
|
||||
|
@ -441,9 +441,8 @@ void GTextDocument::update_undo_timer()
|
|||
GTextPosition GTextDocument::insert_at(const GTextPosition& position, const StringView& text)
|
||||
{
|
||||
GTextPosition cursor = position;
|
||||
for (int i = 0; i < text.length(); ++i) {
|
||||
for (size_t i = 0; i < text.length(); ++i)
|
||||
cursor = insert_at(cursor, text[i]);
|
||||
}
|
||||
return cursor;
|
||||
}
|
||||
|
||||
|
@ -451,7 +450,7 @@ GTextPosition GTextDocument::insert_at(const GTextPosition& position, char ch)
|
|||
{
|
||||
// FIXME: We need these from GTextEditor!
|
||||
bool m_automatic_indentation_enabled = true;
|
||||
int m_soft_tab_width = 4;
|
||||
size_t m_soft_tab_width = 4;
|
||||
|
||||
bool at_head = position.column() == 0;
|
||||
bool at_tail = position.column() == line(position.line()).length();
|
||||
|
@ -459,9 +458,9 @@ GTextPosition GTextDocument::insert_at(const GTextPosition& position, char ch)
|
|||
if (at_tail || at_head) {
|
||||
String new_line_contents;
|
||||
if (m_automatic_indentation_enabled && at_tail) {
|
||||
int leading_spaces = 0;
|
||||
size_t leading_spaces = 0;
|
||||
auto& old_line = lines()[position.line()];
|
||||
for (int i = 0; i < old_line.length(); ++i) {
|
||||
for (size_t i = 0; i < old_line.length(); ++i) {
|
||||
if (old_line.characters()[i] == ' ')
|
||||
++leading_spaces;
|
||||
else
|
||||
|
@ -471,9 +470,9 @@ GTextPosition GTextDocument::insert_at(const GTextPosition& position, char ch)
|
|||
new_line_contents = String::repeated(' ', leading_spaces);
|
||||
}
|
||||
|
||||
int row = position.line();
|
||||
size_t row = position.line();
|
||||
Vector<char> line_content;
|
||||
for (int i = position.column(); i < line(row).length(); i++)
|
||||
for (size_t i = position.column(); i < line(row).length(); i++)
|
||||
line_content.append(line(row).characters()[i]);
|
||||
insert_line(position.line() + (at_tail ? 1 : 0), make<GTextDocumentLine>(*this, new_line_contents));
|
||||
notify_did_change();
|
||||
|
@ -483,7 +482,7 @@ GTextPosition GTextDocument::insert_at(const GTextPosition& position, char ch)
|
|||
new_line->append(*this, line(position.line()).characters() + position.column(), line(position.line()).length() - position.column());
|
||||
|
||||
Vector<char> line_content;
|
||||
for (int i = 0; i < new_line->length(); i++)
|
||||
for (size_t i = 0; i < new_line->length(); i++)
|
||||
line_content.append(new_line->characters()[i]);
|
||||
line(position.line()).truncate(*this, position.column());
|
||||
insert_line(position.line() + 1, move(new_line));
|
||||
|
@ -491,9 +490,9 @@ GTextPosition GTextDocument::insert_at(const GTextPosition& position, char ch)
|
|||
return { position.line() + 1, 0 };
|
||||
}
|
||||
if (ch == '\t') {
|
||||
int next_soft_tab_stop = ((position.column() + m_soft_tab_width) / m_soft_tab_width) * m_soft_tab_width;
|
||||
int spaces_to_insert = next_soft_tab_stop - position.column();
|
||||
for (int i = 0; i < spaces_to_insert; ++i) {
|
||||
size_t next_soft_tab_stop = ((position.column() + m_soft_tab_width) / m_soft_tab_width) * m_soft_tab_width;
|
||||
size_t spaces_to_insert = next_soft_tab_stop - position.column();
|
||||
for (size_t i = 0; i < spaces_to_insert; ++i) {
|
||||
line(position.line()).insert(*this, position.column(), ' ');
|
||||
}
|
||||
notify_did_change();
|
||||
|
@ -512,14 +511,14 @@ void GTextDocument::remove(const GTextRange& unnormalized_range)
|
|||
auto range = unnormalized_range.normalized();
|
||||
|
||||
// First delete all the lines in between the first and last one.
|
||||
for (int i = range.start().line() + 1; i < range.end().line();) {
|
||||
for (size_t i = range.start().line() + 1; i < range.end().line();) {
|
||||
remove_line(i);
|
||||
range.end().set_line(range.end().line() - 1);
|
||||
}
|
||||
|
||||
if (range.start().line() == range.end().line()) {
|
||||
// Delete within same line.
|
||||
auto& line = lines()[range.start().line()];
|
||||
auto& line = this->line(range.start().line());
|
||||
bool whole_line_is_selected = range.start().column() == 0 && range.end().column() == line.length();
|
||||
|
||||
if (whole_line_is_selected) {
|
||||
|
@ -535,8 +534,8 @@ void GTextDocument::remove(const GTextRange& unnormalized_range)
|
|||
} else {
|
||||
// Delete across a newline, merging lines.
|
||||
ASSERT(range.start().line() == range.end().line() - 1);
|
||||
auto& first_line = lines()[range.start().line()];
|
||||
auto& second_line = lines()[range.end().line()];
|
||||
auto& first_line = line(range.start().line());
|
||||
auto& second_line = line(range.end().line());
|
||||
auto before_selection = String(first_line.characters(), first_line.length()).substring(0, range.start().column());
|
||||
auto after_selection = String(second_line.characters(), second_line.length()).substring(range.end().column(), second_line.length() - range.end().column());
|
||||
StringBuilder builder(before_selection.length() + after_selection.length());
|
||||
|
|
|
@ -66,8 +66,8 @@ public:
|
|||
public:
|
||||
virtual ~Client();
|
||||
virtual void document_did_append_line() = 0;
|
||||
virtual void document_did_insert_line(int) = 0;
|
||||
virtual void document_did_remove_line(int) = 0;
|
||||
virtual void document_did_insert_line(size_t) = 0;
|
||||
virtual void document_did_remove_line(size_t) = 0;
|
||||
virtual void document_did_remove_all_lines() = 0;
|
||||
virtual void document_did_change() = 0;
|
||||
virtual void document_did_set_text() = 0;
|
||||
|
@ -79,9 +79,9 @@ public:
|
|||
return adopt(*new GTextDocument(client));
|
||||
}
|
||||
|
||||
int line_count() const { return m_lines.size(); }
|
||||
const GTextDocumentLine& line(int line_index) const { return m_lines[line_index]; }
|
||||
GTextDocumentLine& line(int line_index) { return m_lines[line_index]; }
|
||||
size_t line_count() const { return (size_t)m_lines.size(); }
|
||||
const GTextDocumentLine& line(size_t line_index) const { return m_lines[(int)line_index]; }
|
||||
GTextDocumentLine& line(size_t line_index) { return m_lines[(int)line_index]; }
|
||||
|
||||
void set_spans(const Vector<GTextDocumentSpan>& spans) { m_spans = spans; }
|
||||
|
||||
|
@ -92,12 +92,12 @@ public:
|
|||
|
||||
bool has_spans() const { return !m_spans.is_empty(); }
|
||||
const Vector<GTextDocumentSpan>& spans() const { return m_spans; }
|
||||
void set_span_at_index(int index, GTextDocumentSpan span) { m_spans[index] = move(span); }
|
||||
void set_span_at_index(size_t index, GTextDocumentSpan span) { m_spans[(int)index] = move(span); }
|
||||
|
||||
void append_line(NonnullOwnPtr<GTextDocumentLine>);
|
||||
void remove_line(int line_index);
|
||||
void remove_line(size_t line_index);
|
||||
void remove_all_lines();
|
||||
void insert_line(int line_index, NonnullOwnPtr<GTextDocumentLine>);
|
||||
void insert_line(size_t line_index, NonnullOwnPtr<GTextDocumentLine>);
|
||||
|
||||
void register_client(Client&);
|
||||
void unregister_client(Client&);
|
||||
|
@ -156,18 +156,18 @@ public:
|
|||
explicit GTextDocumentLine(GTextDocument&);
|
||||
explicit GTextDocumentLine(GTextDocument&, const StringView&);
|
||||
|
||||
StringView view() const { return { characters(), length() }; }
|
||||
StringView view() const { return { characters(), (size_t)length() }; }
|
||||
const char* characters() const { return m_text.data(); }
|
||||
int length() const { return m_text.size() - 1; }
|
||||
size_t length() const { return (size_t)m_text.size() - 1; }
|
||||
void set_text(GTextDocument&, const StringView&);
|
||||
void append(GTextDocument&, char);
|
||||
void prepend(GTextDocument&, char);
|
||||
void insert(GTextDocument&, int index, char);
|
||||
void remove(GTextDocument&, int index);
|
||||
void append(GTextDocument&, const char*, int);
|
||||
void truncate(GTextDocument&, int length);
|
||||
void insert(GTextDocument&, size_t index, char);
|
||||
void remove(GTextDocument&, size_t index);
|
||||
void append(GTextDocument&, const char*, size_t);
|
||||
void truncate(GTextDocument&, size_t length);
|
||||
void clear(GTextDocument&);
|
||||
int first_non_whitespace_column() const;
|
||||
size_t first_non_whitespace_column() const;
|
||||
|
||||
private:
|
||||
// NOTE: This vector is null terminated.
|
||||
|
|
|
@ -97,30 +97,30 @@ GTextPosition GTextEditor::text_position_at(const Point& a_position) const
|
|||
position.move_by(-(m_horizontal_content_padding + ruler_width()), 0);
|
||||
position.move_by(-frame_thickness(), -frame_thickness());
|
||||
|
||||
int line_index = -1;
|
||||
size_t line_index = 0;
|
||||
|
||||
if (is_line_wrapping_enabled()) {
|
||||
for (int i = 0; i < lines().size(); ++i) {
|
||||
for (size_t i = 0; i < line_count(); ++i) {
|
||||
auto& rect = m_line_visual_data[i].visual_rect;
|
||||
if (position.y() >= rect.top() && position.y() <= rect.bottom()) {
|
||||
line_index = i;
|
||||
break;
|
||||
}
|
||||
if (position.y() > rect.bottom())
|
||||
line_index = lines().size() - 1;
|
||||
line_index = line_count() - 1;
|
||||
}
|
||||
} else {
|
||||
line_index = position.y() / line_height();
|
||||
line_index = (size_t)(position.y() / line_height());
|
||||
}
|
||||
|
||||
line_index = max(0, min(line_index, line_count() - 1));
|
||||
line_index = max((size_t)0, min(line_index, line_count() - 1));
|
||||
|
||||
int column_index;
|
||||
size_t column_index;
|
||||
switch (m_text_alignment) {
|
||||
case TextAlignment::CenterLeft:
|
||||
column_index = (position.x() + glyph_width() / 2) / glyph_width();
|
||||
if (is_line_wrapping_enabled()) {
|
||||
for_each_visual_line(line_index, [&](const Rect& rect, const StringView&, int start_of_line) {
|
||||
for_each_visual_line(line_index, [&](const Rect& rect, const StringView&, size_t start_of_line) {
|
||||
if (rect.contains_vertically(position.y())) {
|
||||
column_index += start_of_line;
|
||||
return IterationDecision::Break;
|
||||
|
@ -138,7 +138,7 @@ GTextPosition GTextEditor::text_position_at(const Point& a_position) const
|
|||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
||||
column_index = max(0, min(column_index, lines()[line_index].length()));
|
||||
column_index = max((size_t)0, min(column_index, line(line_index).length()));
|
||||
return { line_index, column_index };
|
||||
}
|
||||
|
||||
|
@ -155,7 +155,7 @@ void GTextEditor::doubleclick_event(GMouseEvent& event)
|
|||
|
||||
auto start = text_position_at(event.position());
|
||||
auto end = start;
|
||||
auto& line = lines()[start.line()];
|
||||
auto& line = this->line(start.line());
|
||||
|
||||
if (!document().has_spans()) {
|
||||
while (start.column() > 0) {
|
||||
|
@ -201,11 +201,11 @@ void GTextEditor::mousedown_event(GMouseEvent& event)
|
|||
if (is_multi_line()) {
|
||||
// select *current* line
|
||||
start = GTextPosition(m_cursor.line(), 0);
|
||||
end = GTextPosition(m_cursor.line(), lines()[m_cursor.line()].length());
|
||||
end = GTextPosition(m_cursor.line(), line(m_cursor.line()).length());
|
||||
} else {
|
||||
// select *whole* line
|
||||
start = GTextPosition(0, 0);
|
||||
end = GTextPosition(line_count() - 1, lines()[line_count() - 1].length());
|
||||
end = GTextPosition(line_count() - 1, line(line_count() - 1).length());
|
||||
}
|
||||
|
||||
m_selection.set(start, end);
|
||||
|
@ -266,7 +266,7 @@ int GTextEditor::ruler_width() const
|
|||
return 5 * font().glyph_width('x') + 4;
|
||||
}
|
||||
|
||||
Rect GTextEditor::ruler_content_rect(int line_index) const
|
||||
Rect GTextEditor::ruler_content_rect(size_t line_index) const
|
||||
{
|
||||
if (!m_ruler_visible)
|
||||
return {};
|
||||
|
@ -318,14 +318,14 @@ void GTextEditor::paint_event(GPaintEvent& event)
|
|||
if (m_ruler_visible)
|
||||
painter.translate(ruler_width(), 0);
|
||||
|
||||
int first_visible_line = text_position_at(event.rect().top_left()).line();
|
||||
int last_visible_line = text_position_at(event.rect().bottom_right()).line();
|
||||
size_t first_visible_line = text_position_at(event.rect().top_left()).line();
|
||||
size_t last_visible_line = text_position_at(event.rect().bottom_right()).line();
|
||||
|
||||
auto selection = normalized_selection();
|
||||
bool has_selection = selection.is_valid();
|
||||
|
||||
if (m_ruler_visible) {
|
||||
for (int i = first_visible_line; i <= last_visible_line; ++i) {
|
||||
for (size_t i = first_visible_line; i <= last_visible_line; ++i) {
|
||||
bool is_current_line = i == m_cursor.line();
|
||||
auto ruler_line_rect = ruler_content_rect(i);
|
||||
painter.draw_text(
|
||||
|
@ -345,12 +345,12 @@ void GTextEditor::paint_event(GPaintEvent& event)
|
|||
};
|
||||
painter.add_clip_rect(text_clip_rect);
|
||||
|
||||
for (int line_index = first_visible_line; line_index <= last_visible_line; ++line_index) {
|
||||
auto& line = lines()[line_index];
|
||||
for (size_t line_index = first_visible_line; line_index <= last_visible_line; ++line_index) {
|
||||
auto& line = this->line(line_index);
|
||||
|
||||
bool physical_line_has_selection = has_selection && line_index >= selection.start().line() && line_index <= selection.end().line();
|
||||
int first_visual_line_with_selection = -1;
|
||||
int last_visual_line_with_selection = -1;
|
||||
size_t first_visual_line_with_selection = 0;
|
||||
size_t last_visual_line_with_selection = 0;
|
||||
if (physical_line_has_selection) {
|
||||
if (selection.start().line() < line_index)
|
||||
first_visual_line_with_selection = 0;
|
||||
|
@ -363,11 +363,11 @@ void GTextEditor::paint_event(GPaintEvent& event)
|
|||
last_visual_line_with_selection = visual_line_containing(line_index, selection.end().column());
|
||||
}
|
||||
|
||||
int selection_start_column_within_line = selection.start().line() == line_index ? selection.start().column() : 0;
|
||||
int selection_end_column_within_line = selection.end().line() == line_index ? selection.end().column() : line.length();
|
||||
size_t selection_start_column_within_line = selection.start().line() == line_index ? selection.start().column() : 0;
|
||||
size_t selection_end_column_within_line = selection.end().line() == line_index ? selection.end().column() : line.length();
|
||||
|
||||
int visual_line_index = 0;
|
||||
for_each_visual_line(line_index, [&](const Rect& visual_line_rect, const StringView& visual_line_text, int start_of_visual_line) {
|
||||
size_t visual_line_index = 0;
|
||||
for_each_visual_line(line_index, [&](const Rect& visual_line_rect, const StringView& visual_line_text, size_t start_of_visual_line) {
|
||||
if (is_multi_line() && line_index == m_cursor.line())
|
||||
painter.fill_rect(visual_line_rect, Color(230, 230, 230));
|
||||
#ifdef DEBUG_GTEXTEDITOR
|
||||
|
@ -379,7 +379,7 @@ void GTextEditor::paint_event(GPaintEvent& event)
|
|||
} else {
|
||||
int advance = font().glyph_width(' ') + font().glyph_spacing();
|
||||
Rect character_rect = { visual_line_rect.location(), { font().glyph_width(' '), line_height() } };
|
||||
for (int i = 0; i < visual_line_text.length(); ++i) {
|
||||
for (size_t i = 0; i < visual_line_text.length(); ++i) {
|
||||
const Font* font = &this->font();
|
||||
Color color;
|
||||
Optional<Color> background_color;
|
||||
|
@ -426,8 +426,8 @@ void GTextEditor::paint_event(GPaintEvent& event)
|
|||
|
||||
painter.fill_rect(selection_rect, Color::from_rgb(0x955233));
|
||||
|
||||
int start_of_selection_within_visual_line = max(0, selection_start_column_within_line - start_of_visual_line);
|
||||
int end_of_selection_within_visual_line = selection_end_column_within_line - start_of_visual_line;
|
||||
size_t start_of_selection_within_visual_line = max((size_t)0, selection_start_column_within_line - start_of_visual_line);
|
||||
size_t end_of_selection_within_visual_line = selection_end_column_within_line - start_of_visual_line;
|
||||
|
||||
StringView visual_selected_text {
|
||||
visual_line_text.characters_without_null_termination() + start_of_selection_within_visual_line,
|
||||
|
@ -465,14 +465,14 @@ void GTextEditor::toggle_selection_if_needed_for_event(const GKeyEvent& event)
|
|||
void GTextEditor::select_all()
|
||||
{
|
||||
GTextPosition start_of_document { 0, 0 };
|
||||
GTextPosition end_of_document { line_count() - 1, lines()[line_count() - 1].length() };
|
||||
GTextPosition end_of_document { line_count() - 1, line(line_count() - 1).length() };
|
||||
m_selection.set(start_of_document, end_of_document);
|
||||
did_update_selection();
|
||||
set_cursor(end_of_document);
|
||||
update();
|
||||
}
|
||||
|
||||
void GTextEditor::get_selection_line_boundaries(int& first_line, int& last_line)
|
||||
void GTextEditor::get_selection_line_boundaries(size_t& first_line, size_t& last_line)
|
||||
{
|
||||
auto selection = normalized_selection();
|
||||
if (!selection.is_valid()) {
|
||||
|
@ -488,15 +488,15 @@ void GTextEditor::get_selection_line_boundaries(int& first_line, int& last_line)
|
|||
|
||||
void GTextEditor::move_selected_lines_up()
|
||||
{
|
||||
int first_line;
|
||||
int last_line;
|
||||
size_t first_line;
|
||||
size_t last_line;
|
||||
get_selection_line_boundaries(first_line, last_line);
|
||||
|
||||
if (first_line == 0)
|
||||
return;
|
||||
|
||||
auto& lines = document().lines();
|
||||
lines.insert(last_line, lines.take(first_line - 1));
|
||||
lines.insert((int)last_line, lines.take((int)first_line - 1));
|
||||
m_cursor = { first_line - 1, 0 };
|
||||
|
||||
if (has_selection()) {
|
||||
|
@ -510,15 +510,15 @@ void GTextEditor::move_selected_lines_up()
|
|||
|
||||
void GTextEditor::move_selected_lines_down()
|
||||
{
|
||||
int first_line;
|
||||
int last_line;
|
||||
size_t first_line;
|
||||
size_t last_line;
|
||||
get_selection_line_boundaries(first_line, last_line);
|
||||
|
||||
auto& lines = document().lines();
|
||||
if (last_line >= (lines.size() - 1))
|
||||
if (last_line >= (size_t)(lines.size() - 1))
|
||||
return;
|
||||
|
||||
lines.insert(first_line, lines.take(last_line + 1));
|
||||
lines.insert((int)first_line, lines.take((int)last_line + 1));
|
||||
m_cursor = { first_line + 1, 0 };
|
||||
|
||||
if (has_selection()) {
|
||||
|
@ -538,14 +538,14 @@ void GTextEditor::sort_selected_lines()
|
|||
if (!has_selection())
|
||||
return;
|
||||
|
||||
int first_line;
|
||||
int last_line;
|
||||
size_t first_line;
|
||||
size_t last_line;
|
||||
get_selection_line_boundaries(first_line, last_line);
|
||||
|
||||
auto& lines = document().lines();
|
||||
|
||||
auto start = lines.begin() + first_line;
|
||||
auto end = lines.begin() + last_line + 1;
|
||||
auto start = lines.begin() + (int)first_line;
|
||||
auto end = lines.begin() + (int)last_line + 1;
|
||||
|
||||
quick_sort(start, end, [](auto& a, auto& b) {
|
||||
return strcmp(a.characters(), b.characters()) < 0;
|
||||
|
@ -577,8 +577,8 @@ void GTextEditor::keydown_event(GKeyEvent& event)
|
|||
move_selected_lines_up();
|
||||
return;
|
||||
}
|
||||
int new_line = m_cursor.line() - 1;
|
||||
int new_column = min(m_cursor.column(), lines()[new_line].length());
|
||||
size_t new_line = m_cursor.line() - 1;
|
||||
size_t new_column = min(m_cursor.column(), line(new_line).length());
|
||||
toggle_selection_if_needed_for_event(event);
|
||||
set_cursor(new_line, new_column);
|
||||
if (event.shift() && m_selection.start().is_valid()) {
|
||||
|
@ -589,13 +589,13 @@ void GTextEditor::keydown_event(GKeyEvent& event)
|
|||
return;
|
||||
}
|
||||
if (event.key() == KeyCode::Key_Down) {
|
||||
if (m_cursor.line() < (lines().size() - 1)) {
|
||||
if (m_cursor.line() < (line_count() - 1)) {
|
||||
if (event.ctrl() && event.shift()) {
|
||||
move_selected_lines_down();
|
||||
return;
|
||||
}
|
||||
int new_line = m_cursor.line() + 1;
|
||||
int new_column = min(m_cursor.column(), lines()[new_line].length());
|
||||
size_t new_line = m_cursor.line() + 1;
|
||||
size_t new_column = min(m_cursor.column(), line(new_line).length());
|
||||
toggle_selection_if_needed_for_event(event);
|
||||
set_cursor(new_line, new_column);
|
||||
if (event.shift() && m_selection.start().is_valid()) {
|
||||
|
@ -607,8 +607,8 @@ void GTextEditor::keydown_event(GKeyEvent& event)
|
|||
}
|
||||
if (event.key() == KeyCode::Key_PageUp) {
|
||||
if (m_cursor.line() > 0) {
|
||||
int new_line = max(0, m_cursor.line() - visible_content_rect().height() / line_height());
|
||||
int new_column = min(m_cursor.column(), lines()[new_line].length());
|
||||
size_t new_line = max((size_t)0, m_cursor.line() - (size_t)visible_content_rect().height() / (size_t)line_height());
|
||||
size_t new_column = min(m_cursor.column(), line(new_line).length());
|
||||
toggle_selection_if_needed_for_event(event);
|
||||
set_cursor(new_line, new_column);
|
||||
if (event.shift() && m_selection.start().is_valid()) {
|
||||
|
@ -619,7 +619,7 @@ void GTextEditor::keydown_event(GKeyEvent& event)
|
|||
return;
|
||||
}
|
||||
if (event.key() == KeyCode::Key_PageDown) {
|
||||
if (m_cursor.line() < (lines().size() - 1)) {
|
||||
if (m_cursor.line() < (line_count() - 1)) {
|
||||
int new_line = min(line_count() - 1, m_cursor.line() + visible_content_rect().height() / line_height());
|
||||
int new_column = min(m_cursor.column(), lines()[new_line].length());
|
||||
toggle_selection_if_needed_for_event(event);
|
||||
|
@ -699,7 +699,7 @@ void GTextEditor::keydown_event(GKeyEvent& event)
|
|||
return;
|
||||
}
|
||||
if (!event.ctrl() && event.key() == KeyCode::Key_Home) {
|
||||
int first_nonspace_column = current_line().first_non_whitespace_column();
|
||||
size_t first_nonspace_column = current_line().first_non_whitespace_column();
|
||||
toggle_selection_if_needed_for_event(event);
|
||||
if (m_cursor.column() == first_nonspace_column)
|
||||
set_cursor(m_cursor.line(), 0);
|
||||
|
@ -773,7 +773,7 @@ void GTextEditor::keydown_event(GKeyEvent& event)
|
|||
}
|
||||
if (m_cursor.column() == 0 && m_cursor.line() != 0) {
|
||||
// Backspace at column 0; merge with previous line
|
||||
int previous_length = line(m_cursor.line() - 1).length();
|
||||
size_t previous_length = line(m_cursor.line() - 1).length();
|
||||
GTextRange erased_range({ m_cursor.line() - 1, previous_length }, m_cursor);
|
||||
execute<RemoveTextCommand>("\n", erased_range);
|
||||
return;
|
||||
|
@ -806,10 +806,10 @@ void GTextEditor::delete_current_line()
|
|||
|
||||
GTextPosition start;
|
||||
GTextPosition end;
|
||||
if (m_cursor.line() == 0 && lines().size() == 1) {
|
||||
if (m_cursor.line() == 0 && line_count() == 1) {
|
||||
start = { 0, 0 };
|
||||
end = { 0, line(0).length() };
|
||||
} else if (m_cursor.line() == lines().size() - 1) {
|
||||
} else if (m_cursor.line() == line_count() - 1) {
|
||||
start = { m_cursor.line() - 1, line(m_cursor.line()).length() };
|
||||
end = { m_cursor.line(), line(m_cursor.line()).length() };
|
||||
} else {
|
||||
|
@ -845,11 +845,11 @@ void GTextEditor::do_delete()
|
|||
|
||||
int GTextEditor::content_x_for_position(const GTextPosition& position) const
|
||||
{
|
||||
auto& line = lines()[position.line()];
|
||||
auto& line = this->line(position.line());
|
||||
int x_offset = -1;
|
||||
switch (m_text_alignment) {
|
||||
case TextAlignment::CenterLeft:
|
||||
for_each_visual_line(position.line(), [&](const Rect&, const StringView& view, int start_of_visual_line) {
|
||||
for_each_visual_line(position.line(), [&](const Rect&, const StringView& view, size_t start_of_visual_line) {
|
||||
if (position.column() >= start_of_visual_line && ((position.column() - start_of_visual_line) <= view.length())) {
|
||||
x_offset = (position.column() - start_of_visual_line) * glyph_width();
|
||||
return IterationDecision::Break;
|
||||
|
@ -882,7 +882,7 @@ Rect GTextEditor::content_rect_for_position(const GTextPosition& position) const
|
|||
}
|
||||
|
||||
Rect rect;
|
||||
for_each_visual_line(position.line(), [&](const Rect& visual_line_rect, const StringView& view, int start_of_visual_line) {
|
||||
for_each_visual_line(position.line(), [&](const Rect& visual_line_rect, const StringView& view, size_t start_of_visual_line) {
|
||||
if (position.column() >= start_of_visual_line && ((position.column() - start_of_visual_line) <= view.length())) {
|
||||
// NOTE: We have to subtract the horizontal padding here since it's part of the visual line rect
|
||||
// *and* included in what we get from content_x_for_position().
|
||||
|
@ -904,7 +904,7 @@ Rect GTextEditor::cursor_content_rect() const
|
|||
return content_rect_for_position(m_cursor);
|
||||
}
|
||||
|
||||
Rect GTextEditor::line_widget_rect(int line_index) const
|
||||
Rect GTextEditor::line_widget_rect(size_t line_index) const
|
||||
{
|
||||
auto rect = line_content_rect(line_index);
|
||||
rect.set_x(frame_thickness());
|
||||
|
@ -920,8 +920,8 @@ void GTextEditor::scroll_position_into_view(const GTextPosition& position)
|
|||
auto rect = content_rect_for_position(position);
|
||||
if (position.column() == 0)
|
||||
rect.set_x(content_x_for_position({ position.line(), 0 }) - 2);
|
||||
else if (position.column() == lines()[position.line()].length())
|
||||
rect.set_x(content_x_for_position({ position.line(), lines()[position.line()].length() }) + 2);
|
||||
else if (position.column() == line(position.line()).length())
|
||||
rect.set_x(content_x_for_position({ position.line(), line(position.line()).length() }) + 2);
|
||||
scroll_into_view(rect, true, true);
|
||||
}
|
||||
|
||||
|
@ -930,11 +930,11 @@ void GTextEditor::scroll_cursor_into_view()
|
|||
scroll_position_into_view(m_cursor);
|
||||
}
|
||||
|
||||
Rect GTextEditor::line_content_rect(int line_index) const
|
||||
Rect GTextEditor::line_content_rect(size_t line_index) const
|
||||
{
|
||||
auto& line = lines()[line_index];
|
||||
auto& line = this->line(line_index);
|
||||
if (is_single_line()) {
|
||||
Rect line_rect = { content_x_for_position({ line_index, 0 }), 0, line.length() * glyph_width(), font().glyph_height() + 2 };
|
||||
Rect line_rect = { content_x_for_position({ line_index, 0 }), 0, (int)line.length() * glyph_width(), font().glyph_height() + 2 };
|
||||
line_rect.center_vertically_within({ {}, frame_inner_rect().size() });
|
||||
return line_rect;
|
||||
}
|
||||
|
@ -942,8 +942,8 @@ Rect GTextEditor::line_content_rect(int line_index) const
|
|||
return m_line_visual_data[line_index].visual_rect;
|
||||
return {
|
||||
content_x_for_position({ line_index, 0 }),
|
||||
line_index * line_height(),
|
||||
line.length() * glyph_width(),
|
||||
(int)line_index * line_height(),
|
||||
(int)line.length() * glyph_width(),
|
||||
line_height()
|
||||
};
|
||||
}
|
||||
|
@ -953,7 +953,7 @@ void GTextEditor::update_cursor()
|
|||
update(line_widget_rect(m_cursor.line()));
|
||||
}
|
||||
|
||||
void GTextEditor::set_cursor(int line, int column)
|
||||
void GTextEditor::set_cursor(size_t line, size_t column)
|
||||
{
|
||||
set_cursor({ line, column });
|
||||
}
|
||||
|
@ -964,15 +964,15 @@ void GTextEditor::set_cursor(const GTextPosition& a_position)
|
|||
|
||||
GTextPosition position = a_position;
|
||||
|
||||
if (position.line() >= lines().size())
|
||||
position.set_line(lines().size() - 1);
|
||||
if (position.line() >= line_count())
|
||||
position.set_line(line_count() - 1);
|
||||
|
||||
if (position.column() > lines()[position.line()].length())
|
||||
position.set_column(lines()[position.line()].length());
|
||||
|
||||
if (m_cursor != position) {
|
||||
// NOTE: If the old cursor is no longer valid, repaint everything just in case.
|
||||
auto old_cursor_line_rect = m_cursor.line() < lines().size()
|
||||
auto old_cursor_line_rect = m_cursor.line() < line_count()
|
||||
? line_widget_rect(m_cursor.line())
|
||||
: rect();
|
||||
m_cursor = position;
|
||||
|
@ -1015,9 +1015,9 @@ bool GTextEditor::write_to_file(const StringView& path)
|
|||
// Compute the final file size and ftruncate() to make writing fast.
|
||||
// FIXME: Remove this once the kernel is smart enough to do this instead.
|
||||
off_t file_size = 0;
|
||||
for (int i = 0; i < lines().size(); ++i)
|
||||
file_size += lines()[i].length();
|
||||
file_size += lines().size() - 1;
|
||||
for (size_t i = 0; i < line_count(); ++i)
|
||||
file_size += line(i).length();
|
||||
file_size += line_count() - 1;
|
||||
|
||||
int rc = ftruncate(fd, file_size);
|
||||
if (rc < 0) {
|
||||
|
@ -1025,8 +1025,8 @@ bool GTextEditor::write_to_file(const StringView& path)
|
|||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < lines().size(); ++i) {
|
||||
auto& line = lines()[i];
|
||||
for (size_t i = 0; i < line_count(); ++i) {
|
||||
auto& line = this->line(i);
|
||||
if (line.length()) {
|
||||
ssize_t nwritten = write(fd, line.characters(), line.length());
|
||||
if (nwritten < 0) {
|
||||
|
@ -1035,7 +1035,7 @@ bool GTextEditor::write_to_file(const StringView& path)
|
|||
return false;
|
||||
}
|
||||
}
|
||||
if (i != lines().size() - 1) {
|
||||
if (i != line_count() - 1) {
|
||||
char ch = '\n';
|
||||
ssize_t nwritten = write(fd, &ch, 1);
|
||||
if (nwritten != 1) {
|
||||
|
@ -1053,8 +1053,8 @@ bool GTextEditor::write_to_file(const StringView& path)
|
|||
String GTextEditor::text() const
|
||||
{
|
||||
StringBuilder builder;
|
||||
for (int i = 0; i < line_count(); ++i) {
|
||||
auto& line = lines()[i];
|
||||
for (size_t i = 0; i < line_count(); ++i) {
|
||||
auto& line = this->line(i);
|
||||
builder.append(line.characters(), line.length());
|
||||
if (i != line_count() - 1)
|
||||
builder.append('\n');
|
||||
|
@ -1234,7 +1234,7 @@ void GTextEditor::clear_selection()
|
|||
void GTextEditor::recompute_all_visual_lines()
|
||||
{
|
||||
int y_offset = 0;
|
||||
for (int line_index = 0; line_index < line_count(); ++line_index) {
|
||||
for (size_t line_index = 0; line_index < line_count(); ++line_index) {
|
||||
recompute_visual_lines(line_index);
|
||||
m_line_visual_data[line_index].visual_rect.set_y(y_offset);
|
||||
y_offset += m_line_visual_data[line_index].visual_rect.height();
|
||||
|
@ -1246,18 +1246,18 @@ void GTextEditor::recompute_all_visual_lines()
|
|||
void GTextEditor::ensure_cursor_is_valid()
|
||||
{
|
||||
auto new_cursor = m_cursor;
|
||||
if (new_cursor.line() >= lines().size())
|
||||
new_cursor.set_line(lines().size() - 1);
|
||||
if (new_cursor.column() > lines()[new_cursor.line()].length())
|
||||
new_cursor.set_column(lines()[new_cursor.line()].length());
|
||||
if (new_cursor.line() >= line_count())
|
||||
new_cursor.set_line(line_count() - 1);
|
||||
if (new_cursor.column() > line(new_cursor.line()).length())
|
||||
new_cursor.set_column(line(new_cursor.line()).length());
|
||||
if (m_cursor != new_cursor)
|
||||
set_cursor(new_cursor);
|
||||
}
|
||||
|
||||
int GTextEditor::visual_line_containing(int line_index, int column) const
|
||||
size_t GTextEditor::visual_line_containing(size_t line_index, size_t column) const
|
||||
{
|
||||
int visual_line_index = 0;
|
||||
for_each_visual_line(line_index, [&](const Rect&, const StringView& view, int start_of_visual_line) {
|
||||
size_t visual_line_index = 0;
|
||||
for_each_visual_line(line_index, [&](const Rect&, const StringView& view, size_t start_of_visual_line) {
|
||||
if (column >= start_of_visual_line && ((column - start_of_visual_line) < view.length()))
|
||||
return IterationDecision::Break;
|
||||
++visual_line_index;
|
||||
|
@ -1266,7 +1266,7 @@ int GTextEditor::visual_line_containing(int line_index, int column) const
|
|||
return visual_line_index;
|
||||
}
|
||||
|
||||
void GTextEditor::recompute_visual_lines(int line_index)
|
||||
void GTextEditor::recompute_visual_lines(size_t line_index)
|
||||
{
|
||||
auto& line = document().line(line_index);
|
||||
auto& visual_data = m_line_visual_data[line_index];
|
||||
|
@ -1278,7 +1278,7 @@ void GTextEditor::recompute_visual_lines(int line_index)
|
|||
if (is_line_wrapping_enabled()) {
|
||||
int line_width_so_far = 0;
|
||||
|
||||
for (int i = 0; i < line.length(); ++i) {
|
||||
for (size_t i = 0; i < line.length(); ++i) {
|
||||
auto ch = line.characters()[i];
|
||||
auto glyph_width = font().glyph_width(ch);
|
||||
if ((line_width_so_far + glyph_width) > available_width) {
|
||||
|
@ -1299,11 +1299,11 @@ void GTextEditor::recompute_visual_lines(int line_index)
|
|||
}
|
||||
|
||||
template<typename Callback>
|
||||
void GTextEditor::for_each_visual_line(int line_index, Callback callback) const
|
||||
void GTextEditor::for_each_visual_line(size_t line_index, Callback callback) const
|
||||
{
|
||||
auto editor_visible_text_rect = visible_text_rect_in_inner_coordinates();
|
||||
int start_of_line = 0;
|
||||
int visual_line_index = 0;
|
||||
size_t start_of_line = 0;
|
||||
size_t visual_line_index = 0;
|
||||
|
||||
auto& line = document().line(line_index);
|
||||
auto& visual_data = m_line_visual_data[line_index];
|
||||
|
@ -1312,7 +1312,7 @@ void GTextEditor::for_each_visual_line(int line_index, Callback callback) const
|
|||
auto visual_line_view = StringView(line.characters() + start_of_line, visual_line_break - start_of_line);
|
||||
Rect visual_line_rect {
|
||||
visual_data.visual_rect.x(),
|
||||
visual_data.visual_rect.y() + (visual_line_index * line_height()),
|
||||
visual_data.visual_rect.y() + ((int)visual_line_index * line_height()),
|
||||
font().width(visual_line_view),
|
||||
line_height()
|
||||
};
|
||||
|
@ -1357,7 +1357,7 @@ void GTextEditor::document_did_append_line()
|
|||
update();
|
||||
}
|
||||
|
||||
void GTextEditor::document_did_remove_line(int line_index)
|
||||
void GTextEditor::document_did_remove_line(size_t line_index)
|
||||
{
|
||||
m_line_visual_data.remove(line_index);
|
||||
recompute_all_visual_lines();
|
||||
|
@ -1371,7 +1371,7 @@ void GTextEditor::document_did_remove_all_lines()
|
|||
update();
|
||||
}
|
||||
|
||||
void GTextEditor::document_did_insert_line(int line_index)
|
||||
void GTextEditor::document_did_insert_line(size_t line_index)
|
||||
{
|
||||
m_line_visual_data.insert(line_index, make<LineVisualData>());
|
||||
recompute_all_visual_lines();
|
||||
|
@ -1387,7 +1387,7 @@ void GTextEditor::document_did_change()
|
|||
void GTextEditor::document_did_set_text()
|
||||
{
|
||||
m_line_visual_data.clear();
|
||||
for (int i = 0; i < m_document->line_count(); ++i)
|
||||
for (size_t i = 0; i < m_document->line_count(); ++i)
|
||||
m_line_visual_data.append(make<LineVisualData>());
|
||||
document_did_change();
|
||||
}
|
||||
|
@ -1405,7 +1405,7 @@ void GTextEditor::set_document(GTextDocument& document)
|
|||
m_document->unregister_client(*this);
|
||||
m_document = document;
|
||||
m_line_visual_data.clear();
|
||||
for (int i = 0; i < m_document->line_count(); ++i) {
|
||||
for (size_t i = 0; i < m_document->line_count(); ++i) {
|
||||
m_line_visual_data.append(make<LineVisualData>());
|
||||
}
|
||||
m_cursor = { 0, 0 };
|
||||
|
|
|
@ -56,7 +56,7 @@ public:
|
|||
void set_text(const StringView&);
|
||||
void scroll_cursor_into_view();
|
||||
void scroll_position_into_view(const GTextPosition&);
|
||||
int line_count() const { return document().line_count(); }
|
||||
size_t line_count() const { return document().line_count(); }
|
||||
int line_spacing() const { return m_line_spacing; }
|
||||
int line_height() const { return font().glyph_height() + m_line_spacing; }
|
||||
GTextPosition cursor() const { return m_cursor; }
|
||||
|
@ -99,7 +99,7 @@ public:
|
|||
|
||||
void add_custom_context_menu_action(GAction&);
|
||||
|
||||
void set_cursor(int line, int column);
|
||||
void set_cursor(size_t line, size_t column);
|
||||
void set_cursor(const GTextPosition&);
|
||||
|
||||
protected:
|
||||
|
@ -130,8 +130,8 @@ private:
|
|||
|
||||
// ^GTextDocument::Client
|
||||
virtual void document_did_append_line() override;
|
||||
virtual void document_did_insert_line(int) override;
|
||||
virtual void document_did_remove_line(int) override;
|
||||
virtual void document_did_insert_line(size_t) override;
|
||||
virtual void document_did_remove_line(size_t) override;
|
||||
virtual void document_did_remove_all_lines() override;
|
||||
virtual void document_did_change() override;
|
||||
virtual void document_did_set_text() override;
|
||||
|
@ -142,19 +142,19 @@ private:
|
|||
void update_content_size();
|
||||
void did_change();
|
||||
|
||||
Rect line_content_rect(int item_index) const;
|
||||
Rect line_widget_rect(int line_index) const;
|
||||
Rect line_content_rect(size_t item_index) const;
|
||||
Rect line_widget_rect(size_t line_index) const;
|
||||
Rect cursor_content_rect() const;
|
||||
Rect content_rect_for_position(const GTextPosition&) const;
|
||||
void update_cursor();
|
||||
const NonnullOwnPtrVector<GTextDocumentLine>& lines() const { return document().lines(); }
|
||||
NonnullOwnPtrVector<GTextDocumentLine>& lines() { return document().lines(); }
|
||||
GTextDocumentLine& line(int index) { return document().line(index); }
|
||||
const GTextDocumentLine& line(int index) const { return document().line(index); }
|
||||
GTextDocumentLine& line(size_t index) { return document().line(index); }
|
||||
const GTextDocumentLine& line(size_t index) const { return document().line(index); }
|
||||
GTextDocumentLine& current_line() { return line(m_cursor.line()); }
|
||||
const GTextDocumentLine& current_line() const { return line(m_cursor.line()); }
|
||||
int ruler_width() const;
|
||||
Rect ruler_content_rect(int line) const;
|
||||
Rect ruler_content_rect(size_t line) const;
|
||||
void toggle_selection_if_needed_for_event(const GKeyEvent&);
|
||||
void insert_at_cursor_or_replace_selection(const StringView&);
|
||||
void delete_selection();
|
||||
|
@ -165,13 +165,13 @@ private:
|
|||
void recompute_all_visual_lines();
|
||||
void ensure_cursor_is_valid();
|
||||
void flush_pending_change_notification_if_needed();
|
||||
void get_selection_line_boundaries(int& first_line, int& last_line);
|
||||
void get_selection_line_boundaries(size_t& first_line, size_t& last_line);
|
||||
void move_selected_lines_up();
|
||||
void move_selected_lines_down();
|
||||
void sort_selected_lines();
|
||||
|
||||
int visual_line_containing(int line_index, int column) const;
|
||||
void recompute_visual_lines(int line_index);
|
||||
size_t visual_line_containing(size_t line_index, size_t column) const;
|
||||
void recompute_visual_lines(size_t line_index);
|
||||
|
||||
template<class T, class... Args>
|
||||
inline void execute(Args&&... args)
|
||||
|
@ -193,7 +193,7 @@ private:
|
|||
bool m_line_wrapping_enabled { false };
|
||||
bool m_readonly { false };
|
||||
int m_line_spacing { 4 };
|
||||
int m_soft_tab_width { 4 };
|
||||
size_t m_soft_tab_width { 4 };
|
||||
int m_horizontal_content_padding { 2 };
|
||||
GTextRange m_selection;
|
||||
OwnPtr<GMenu> m_context_menu;
|
||||
|
@ -209,10 +209,10 @@ private:
|
|||
RefPtr<GTextDocument> m_document;
|
||||
|
||||
template<typename Callback>
|
||||
void for_each_visual_line(int line_index, Callback) const;
|
||||
void for_each_visual_line(size_t line_index, Callback) const;
|
||||
|
||||
struct LineVisualData {
|
||||
Vector<int, 1> visual_line_breaks;
|
||||
Vector<size_t, 1> visual_line_breaks;
|
||||
Rect visual_rect;
|
||||
};
|
||||
|
||||
|
|
|
@ -6,32 +6,32 @@
|
|||
class GTextPosition {
|
||||
public:
|
||||
GTextPosition() {}
|
||||
GTextPosition(int line, int column)
|
||||
GTextPosition(size_t line, size_t column)
|
||||
: m_line(line)
|
||||
, m_column(column)
|
||||
{
|
||||
}
|
||||
|
||||
bool is_valid() const { return m_line >= 0 && m_column >= 0; }
|
||||
bool is_valid() const { return m_line != 0xffffffffu && m_column != 0xffffffffu; }
|
||||
|
||||
int line() const { return m_line; }
|
||||
int column() const { return m_column; }
|
||||
size_t line() const { return m_line; }
|
||||
size_t column() const { return m_column; }
|
||||
|
||||
void set_line(int line) { m_line = line; }
|
||||
void set_column(int column) { m_column = column; }
|
||||
void set_line(size_t line) { m_line = line; }
|
||||
void set_column(size_t column) { m_column = column; }
|
||||
|
||||
bool operator==(const GTextPosition& other) const { return m_line == other.m_line && m_column == other.m_column; }
|
||||
bool operator!=(const GTextPosition& other) const { return m_line != other.m_line || m_column != other.m_column; }
|
||||
bool operator<(const GTextPosition& other) const { return m_line < other.m_line || (m_line == other.m_line && m_column < other.m_column); }
|
||||
|
||||
private:
|
||||
int m_line { -1 };
|
||||
int m_column { -1 };
|
||||
size_t m_line { 0xffffffff };
|
||||
size_t m_column { 0xffffffff };
|
||||
};
|
||||
|
||||
inline const LogStream& operator<<(const LogStream& stream, const GTextPosition& value)
|
||||
{
|
||||
if (!value.is_valid())
|
||||
return stream << "GTextPosition(Invalid)";
|
||||
return stream << String::format("(%d,%d)", value.line(), value.column());
|
||||
return stream << String::format("(%zu,%zu)", value.line(), value.column());
|
||||
}
|
||||
|
|
|
@ -338,7 +338,7 @@ void GWindow::paint_keybinds()
|
|||
continue;
|
||||
auto& widget = *keypair.value;
|
||||
bool could_be_keybind = true;
|
||||
for (int i = 0; i < m_entered_keybind.length(); ++i) {
|
||||
for (size_t i = 0; i < m_entered_keybind.length(); ++i) {
|
||||
if (keypair.key.characters()[i] != m_entered_keybind.characters()[i]) {
|
||||
could_be_keybind = false;
|
||||
break;
|
||||
|
|
|
@ -175,7 +175,7 @@ private:
|
|||
bool m_show_titlebar { true };
|
||||
bool m_keybind_mode { false };
|
||||
String m_entered_keybind;
|
||||
int m_max_keybind_length { 0 };
|
||||
size_t m_max_keybind_length { 0 };
|
||||
HashMap<String, WeakPtr<GWidget>> m_keyboard_activation_targets;
|
||||
bool m_layout_pending { false };
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue