Skip to content

Commit

Permalink
add drag to select support
Browse files Browse the repository at this point in the history
  • Loading branch information
reykjalin committed Mar 24, 2024
1 parent df5577a commit 710bf44
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
use std::sync::mpsc::{channel, Receiver, Sender};
use std::time::Duration;

use egui::text::{CCursor, CCursorRange};
use egui::text::CCursorRange;
use egui::Rect;
use egui::{
text::{CursorRange, LayoutJob},
text_selection::text_cursor_state::{ccursor_next_word, ccursor_previous_word},
vec2, Align2, Event, EventFilter, FontId, Key, Margin, NumExt, Sense, Shape, TextBuffer,
TextFormat, Vec2,
};
use epaint::text::cursor::Cursor;

/// We derive Deserialize/Serialize so we can persist app state on shutdown.
#[derive(serde::Deserialize, serde::Serialize)]
Expand Down Expand Up @@ -279,8 +278,13 @@ impl eframe::App for TemplateApp {
content_ui.memory_mut(|m| m.request_focus(response.id));
}

if let Some(pointer_pos) = ui.ctx().pointer_interact_pos() {
if response.is_pointer_button_down_on() {
if let Some(pointer_pos) = content_ui.ctx().pointer_interact_pos() {
if response.is_pointer_button_down_on() && response.dragged() {
self.selection = CursorRange {
primary: galley.cursor_from_pos(pointer_pos - response.rect.min),
secondary: self.selection.secondary,
};
} else if response.is_pointer_button_down_on() {
self.selection = CursorRange {
primary: galley.cursor_from_pos(pointer_pos - response.rect.min),
secondary: galley.cursor_from_pos(pointer_pos - response.rect.min),
Expand Down

0 comments on commit 710bf44

Please sign in to comment.