2017-01-23 06:19:43 +00:00
|
|
|
/*
|
2018-05-10 08:12:47 +00:00
|
|
|
4coder_seek.cpp - Procedures and commands for jumping through code to useful stop boundaries.
|
|
|
|
*/
|
2017-01-23 06:19:43 +00:00
|
|
|
|
|
|
|
// TOP
|
|
|
|
|
2019-06-05 23:04:35 +00:00
|
|
|
internal void
|
|
|
|
seek_pos_of_textual_line(Application_Links *app, Side side){
|
2019-06-19 02:31:59 +00:00
|
|
|
View_ID view = get_active_view(app, AccessProtected);
|
2019-06-20 23:43:27 +00:00
|
|
|
Buffer_ID buffer = view_get_buffer(app, view, AccessProtected);
|
|
|
|
i64 pos = view_get_cursor_pos(app, view);
|
|
|
|
i64 new_pos = get_line_side_pos_from_pos(app, buffer, pos, side);
|
2019-09-02 21:32:52 +00:00
|
|
|
view_set_cursor_and_preferred_x(app, view, seek_pos(new_pos));
|
2019-04-06 21:13:49 +00:00
|
|
|
no_mark_snap_to_cursor_if_shift(app, view);
|
2018-05-10 08:12:47 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 23:04:35 +00:00
|
|
|
internal void
|
|
|
|
seek_pos_of_visual_line(Application_Links *app, Side side){
|
2019-06-19 02:31:59 +00:00
|
|
|
View_ID view = get_active_view(app, AccessProtected);
|
2019-06-20 23:43:27 +00:00
|
|
|
i64 pos = view_get_cursor_pos(app, view);
|
2019-09-02 18:59:36 +00:00
|
|
|
Buffer_Cursor cursor = view_compute_cursor(app, view, seek_pos(pos));
|
|
|
|
Vec2_f32 p = view_relative_xy_of_pos(app, view, cursor.line, pos);
|
|
|
|
p.x = (side == Side_Min)?(0.f):(max_f32);
|
|
|
|
i64 new_pos = view_pos_at_relative_xy(app, view, cursor.line, p);
|
2019-09-02 21:32:52 +00:00
|
|
|
view_set_cursor_and_preferred_x(app, view, seek_pos(new_pos));
|
2019-04-06 21:13:49 +00:00
|
|
|
no_mark_snap_to_cursor_if_shift(app, view);
|
2018-05-10 08:12:47 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 23:04:35 +00:00
|
|
|
CUSTOM_COMMAND_SIG(seek_beginning_of_textual_line)
|
|
|
|
CUSTOM_DOC("Seeks the cursor to the beginning of the line across all text.")
|
|
|
|
{
|
|
|
|
seek_pos_of_textual_line(app, Side_Min);
|
|
|
|
}
|
|
|
|
|
|
|
|
CUSTOM_COMMAND_SIG(seek_end_of_textual_line)
|
|
|
|
CUSTOM_DOC("Seeks the cursor to the end of the line across all text.")
|
|
|
|
{
|
|
|
|
seek_pos_of_textual_line(app, Side_Max);
|
|
|
|
}
|
|
|
|
|
2018-05-10 08:12:47 +00:00
|
|
|
CUSTOM_COMMAND_SIG(seek_beginning_of_line)
|
|
|
|
CUSTOM_DOC("Seeks the cursor to the beginning of the visual line.")
|
|
|
|
{
|
2019-06-05 23:04:35 +00:00
|
|
|
seek_pos_of_visual_line(app, Side_Min);
|
2018-05-10 08:12:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CUSTOM_COMMAND_SIG(seek_end_of_line)
|
|
|
|
CUSTOM_DOC("Seeks the cursor to the end of the visual line.")
|
|
|
|
{
|
2019-06-05 23:04:35 +00:00
|
|
|
seek_pos_of_visual_line(app, Side_Max);
|
2018-05-10 08:12:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CUSTOM_COMMAND_SIG(goto_beginning_of_file)
|
|
|
|
CUSTOM_DOC("Sets the cursor to the beginning of the file.")
|
|
|
|
{
|
2019-06-19 02:31:59 +00:00
|
|
|
View_ID view = get_active_view(app, AccessProtected);
|
2019-09-02 21:32:52 +00:00
|
|
|
view_set_cursor_and_preferred_x(app, view, seek_pos(0));
|
2019-04-06 21:13:49 +00:00
|
|
|
no_mark_snap_to_cursor_if_shift(app, view);
|
2018-05-10 08:12:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CUSTOM_COMMAND_SIG(goto_end_of_file)
|
|
|
|
CUSTOM_DOC("Sets the cursor to the end of the file.")
|
|
|
|
{
|
2019-06-19 02:31:59 +00:00
|
|
|
View_ID view = get_active_view(app, AccessProtected);
|
|
|
|
Buffer_ID buffer_id = view_get_buffer(app, view, AccessProtected);
|
|
|
|
i32 size = (i32)buffer_get_size(app, buffer_id);
|
2019-09-02 21:32:52 +00:00
|
|
|
view_set_cursor_and_preferred_x(app, view, seek_pos(size));
|
2019-04-06 21:13:49 +00:00
|
|
|
no_mark_snap_to_cursor_if_shift(app, view);
|
2018-05-10 08:12:47 +00:00
|
|
|
}
|
|
|
|
|
2019-02-21 04:43:25 +00:00
|
|
|
// BOTTOM
|
|
|
|
|