summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Libraries/LibLine/Editor.cpp18
-rw-r--r--Libraries/LibLine/Editor.h1
2 files changed, 18 insertions, 1 deletions
diff --git a/Libraries/LibLine/Editor.cpp b/Libraries/LibLine/Editor.cpp
index f91d2a3604..91c4d44e11 100644
--- a/Libraries/LibLine/Editor.cpp
+++ b/Libraries/LibLine/Editor.cpp
@@ -407,6 +407,22 @@ String Editor::get_line(const String& prompt)
}
}
+void Editor::recalculate_origin()
+{
+ // changing the columns can affect our origin if
+ // the new size is smaller than our prompt, which would
+ // cause said prompt to take up more space, so we should
+ // compensate for that
+ if (m_cached_prompt_length >= m_num_columns) {
+ auto added_lines = (m_cached_prompt_length + 1) / m_num_columns - 1;
+ dbg() << "added lines: " << added_lines;
+ m_origin_x += added_lines;
+ }
+
+ // we also need to recalculate our cursor position
+ // but that will be calculated and applied at the next
+ // refresh cycle
+}
void Editor::refresh_display()
{
auto cleanup = [&] {
@@ -436,8 +452,8 @@ void Editor::refresh_display()
m_cached_prompt_valid = false;
m_refresh_needed = true;
swap(previous_num_columns, m_num_columns);
+ recalculate_origin();
cleanup();
- set_origin();
swap(previous_num_columns, m_num_columns);
has_cleaned_up = true;
}
diff --git a/Libraries/LibLine/Editor.h b/Libraries/LibLine/Editor.h
index b5765b0137..6a6c4a000c 100644
--- a/Libraries/LibLine/Editor.h
+++ b/Libraries/LibLine/Editor.h
@@ -168,6 +168,7 @@ private:
m_origin_x = position[0];
m_origin_y = position[1];
}
+ void recalculate_origin();
void reposition_cursor();
Vector<char, 1024> m_buffer;