Skip to content

Commit

Permalink
Fix the bug with selecting commands by mouse
Browse files Browse the repository at this point in the history
  • Loading branch information
focus-editor committed Apr 26, 2023
1 parent 4a8a26d commit 55da123
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
9 changes: 7 additions & 2 deletions LOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@
- Currently only RGB monitor panels

- Release checklist
- Change the version
- Remove the [not implemented]
- Update readme and package it
- Google Analytics?
- Disqus

===========================

- Project commands:
- Open projects folder
- Open global config
- Open project config
- Switch project

- Line wrap:
- Sticky viewport
- When editing with multiple cursors it makes sense to adjust the glue point even for the current buffer
Expand Down
9 changes: 7 additions & 2 deletions src/draw.jai
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ draw_welcome_screen :: (main_area: Rect) {
.{ .search_in_buffer, "Search In Open File" },
.{ .search_in_buffer_dropdown_mode, "Search In Open File (Dropdown Mode)" },
.{ .search_in_project, "Search In Workspace" },
.{ .go_to_line, "Go To Line" },
];

right_area = shrink(right_area, margin);
Expand Down Expand Up @@ -1380,14 +1379,18 @@ draw_commands_dialog :: () {


if mouse_pointer_is_within(entry_rect) && ui.hot_last_frame == ui_id && (ui.active == .none || ui.active == ui_id) {
if mouse.left.just_pressed then selected_by_mouse = entry_index;
if selected_by_mouse == -1 then draw_rect(entry_rect, Colors.LIST_CURSOR_LITE);
draw_rect(entry_rect, Colors.LIST_CURSOR_LITE);

if mouse.left.just_pressed {
if selected_by_mouse == entry_index && mouse.left.just_released {
selected = entry_index;
commands_execute_selected();
redraw_requested = true;
break;
}
}
if selected_by_mouse == entry_index then draw_rect(entry_rect, Colors.LIST_CURSOR);
if entry_index == selected then draw_rect(entry_rect, Colors.LIST_CURSOR);

pen := make_vector2(
Expand Down Expand Up @@ -1420,6 +1423,8 @@ draw_commands_dialog :: () {
}
}

if mouse.left.just_released || !mouse.left.is_down then selected_by_mouse = -1;

if scroll_y != 0 then draw_top_down_shadow(cut_top(entries_rect, char_size));
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main.jai
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION :: "0.1.0-rc";
VERSION :: "0.1.0";
RELEASE_DATE :: "26 April 2023";

main :: () {
Expand Down
18 changes: 14 additions & 4 deletions src/widgets/commands.jai
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,20 @@ commands_execute_selected :: () {
if selected >= filtered.count return;

command := filtered[selected].command;

for * commands { if command.action == it.action { it.num_times_used += 1; break; } }

dummy_event: Input.Event; // TODO: refactor so that this event is not needed
// (need to put the search bar into its own widget for this)
editors_handle_action(dummy_event, command.action);
if command.action == {
case .do_nothing; return;

case .open_projects_directory;
case .open_global_config;
case .open_project_config;
case .switch_project;
case;
dummy_event: Input.Event; // TODO: refactor so that this event is not needed
// (need to put the search bar into its own widget for this)
editors_handle_action(dummy_event, command.action);
}
}

#scope_file
Expand Down Expand Up @@ -153,6 +161,7 @@ commands := #run Command.[

.{ .select_all, "Select All", 0, true },
.{ .select_line, "Select Line", 0, true },
.{ .go_to_line, "Go To Line", 0, true },

.{ .close_current_editor, "Close Current File", 0, true },
.{ .close_other_editor, "Close Other File", 0, true },
Expand Down Expand Up @@ -199,6 +208,7 @@ Commands_Dialog :: struct {
input: Text_Input;
filtered: [..] Entry;
selected: s64;
selected_by_mouse: s64 = -1; // to remember which entry the left mouse button went down on

scroll_y: s32;
scroll_anim := #run Tween_Animation(s32).{ speed = xx 0.1, func = .lerp };
Expand Down

0 comments on commit 55da123

Please sign in to comment.