Change how scrolling works, add home/end (#1212)

Conflicts fixed by gull
This commit is contained in:
Kyle Reed 2023-06-29 13:17:31 -07:00 committed by GitHub
parent ceaa115025
commit ca7840557b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 36 deletions

View file

@ -137,6 +137,16 @@ uint32_t TextViewer::offset() const {
return 0;
}
void TextViewer::cursor_home() {
cursor_.col = 0;
redraw();
}
void TextViewer::cursor_end() {
cursor_.col = line_length() - 1;
redraw();
}
uint16_t TextViewer::line_length() {
return file_->line_length(cursor_.line);
}
@ -157,18 +167,14 @@ bool TextViewer::apply_scrolling_constraints(int16_t delta_line, int16_t delta_c
++new_line;
}
// Snap to first/last to make navigating easier.
if (new_line < 0 && new_col > 0) {
// Snap to first/last line to make navigating easier.
if (new_line < 0 && cursor_.line > 0) {
new_line = 0;
new_col = 0;
} else if (new_line >= (int32_t)file_->line_count()) {
auto last_line = file_->line_count() - 1;
int32_t last_col = file_->line_length(last_line) - 1;
if (new_col < last_col) {
if (cursor_.line < last_line)
new_line = last_line;
new_col = last_col;
}
}
if (new_line < 0 || (uint32_t)new_line >= file_->line_count())
@ -176,7 +182,6 @@ bool TextViewer::apply_scrolling_constraints(int16_t delta_line, int16_t delta_c
new_line_length = file_->line_length(new_line);
// TODO: don't wrap with encoder?
// Wrap or clamp column.
if (new_line_length == 0)
new_col = 0;
@ -267,9 +272,9 @@ TextEditorMenu::TextEditorMenu()
add_children(
{
&rect_frame,
&button_cut,
&button_paste,
&button_zoom,
&button_home,
&button_end,
&button_copy,
&button_delline,
&button_edit,
&button_addline,
@ -318,18 +323,19 @@ TextEditorView::TextEditorView(NavigationView& nav)
};
menu.hidden(true);
menu.on_cut() = [this]() {
show_nyi();
};
menu.on_paste() = [this]() {
show_nyi();
};
menu.on_zoom() = [this]() {
viewer.toggle_font_zoom();
refresh_ui();
menu.on_home() = [this]() {
viewer.cursor_home();
hide_menu(true);
};
menu.on_end() = [this]() {
viewer.cursor_end();
hide_menu(true);
};
menu.on_copy() = [this]() {
};
menu.on_delete_line() = [this]() {
prepare_for_write();
file_->delete_line(viewer.line());
@ -500,10 +506,6 @@ void TextEditorView::show_edit_line() {
});
}
void TextEditorView::show_nyi() {
nav_.display_modal("Soon...", "Coming soon.");
}
void TextEditorView::show_save_prompt(std::function<void()> continuation) {
if (!file_dirty_) {
if (continuation)