Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
Bevy Cosmic Edit
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Microhacks
Bevy Forks
Bevy Cosmic Edit
Commits
c9eb67b0
Unverified
Commit
c9eb67b0
authored
1 year ago
by
sam
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Multi click text selection (#70)
* double + triple click detection * working multi click selection
parent
1aff2fc2
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/input.rs
+80
-36
80 additions, 36 deletions
src/input.rs
src/lib.rs
+2
-1
2 additions, 1 deletion
src/lib.rs
with
82 additions
and
37 deletions
src/input.rs
+
80
−
36
View file @
c9eb67b0
...
...
@@ -3,7 +3,7 @@
use
std
::
time
::
Duration
;
use
bevy
::{
input
::
mouse
::{
MouseScrollUnit
,
MouseWheel
},
input
::
mouse
::{
MouseMotion
,
MouseScrollUnit
,
MouseWheel
},
prelude
::
*
,
window
::
PrimaryWindow
,
};
...
...
@@ -16,28 +16,50 @@ use crate::{
XOffset
,
};
#[derive(Resource)]
pub
struct
ClickTimer
(
pub
Timer
);
pub
(
crate
)
fn
input_mouse
(
windows
:
Query
<&
Window
,
With
<
PrimaryWindow
>>
,
// Mouse
active_editor
:
Res
<
Focus
>
,
// Both
keys
:
Res
<
Input
<
KeyCode
>>
,
// Both
buttons
:
Res
<
Input
<
MouseButton
>>
,
// Mouse
windows
:
Query
<&
Window
,
With
<
PrimaryWindow
>>
,
active_editor
:
Res
<
Focus
>
,
keys
:
Res
<
Input
<
KeyCode
>>
,
buttons
:
Res
<
Input
<
MouseButton
>>
,
mut
cosmic_edit_query
:
Query
<
(
&
mut
CosmicEditor
,
// Both
&
GlobalTransform
,
// Mouse
&
CosmicTextPosition
,
// Mouse, to determine point
Entity
,
// Both
&
XOffset
,
// Mouse
&
mut
CosmicEditor
,
&
GlobalTransform
,
&
CosmicTextPosition
,
Entity
,
&
XOffset
,
Option
<&
mut
Node
>
,
Option
<&
mut
Sprite
>
,
)
>
,
mut
font_system
:
ResMut
<
CosmicFontSystem
>
,
// Both
mut
scroll_evr
:
EventReader
<
MouseWheel
>
,
// Mouse
camera_q
:
Query
<
(
&
Camera
,
&
GlobalTransform
)
>
,
// Mouse
mut
font_system
:
ResMut
<
CosmicFontSystem
>
,
mut
scroll_evr
:
EventReader
<
MouseWheel
>
,
camera_q
:
Query
<
(
&
Camera
,
&
GlobalTransform
)
>
,
mut
click_timer
:
ResMut
<
ClickTimer
>
,
mut
click_count
:
Local
<
usize
>
,
time
:
Res
<
Time
>
,
evr_mouse_motion
:
EventReader
<
MouseMotion
>
,
)
{
click_timer
.0
.tick
(
time
.delta
());
if
active_editor
.0
.is_none
()
{
return
;
}
if
click_timer
.0
.finished
()
||
!
evr_mouse_motion
.is_empty
()
{
*
click_count
=
0
;
}
if
buttons
.just_pressed
(
MouseButton
::
Left
)
{
click_timer
.0
.reset
();
*
click_count
+=
1
;
}
if
*
click_count
>
3
{
*
click_count
=
0
;
}
let
primary_window
=
windows
.single
();
let
scale_factor
=
primary_window
.scale_factor
()
as
f32
;
let
(
camera
,
camera_transform
)
=
camera_q
.iter
()
.find
(|(
c
,
_
)|
c
.is_active
)
.unwrap
();
...
...
@@ -98,12 +120,32 @@ pub(crate) fn input_mouse(
if
shift
{
editor
.0
.action
(
&
mut
font_system
.0
,
Action
::
Drag
{
x
,
y
});
}
else
{
editor
.0
.action
(
&
mut
font_system
.0
,
Action
::
Click
{
x
,
y
});
match
*
click_count
{
1
=>
{
editor
.0
.action
(
&
mut
font_system
.0
,
Action
::
Click
{
x
,
y
});
}
2
=>
{
// select word
editor
.0
.action
(
&
mut
font_system
.0
,
Action
::
LeftWord
);
let
cursor
=
editor
.0
.cursor
();
editor
.0
.set_select_opt
(
Some
(
cursor
));
editor
.0
.action
(
&
mut
font_system
.0
,
Action
::
RightWord
);
}
3
=>
{
// select paragraph
editor
.0
.action
(
&
mut
font_system
.0
,
Action
::
ParagraphStart
);
let
cursor
=
editor
.0
.cursor
();
editor
.0
.set_select_opt
(
Some
(
cursor
));
editor
.0
.action
(
&
mut
font_system
.0
,
Action
::
ParagraphEnd
);
}
_
=>
{}
}
}
}
return
;
}
if
buttons
.pressed
(
MouseButton
::
Left
)
{
if
buttons
.pressed
(
MouseButton
::
Left
)
&&
*
click_count
==
0
{
if
let
Some
(
node_cursor_pos
)
=
get_node_cursor_pos
(
primary_window
,
node_transform
,
...
...
@@ -122,6 +164,7 @@ pub(crate) fn input_mouse(
}
return
;
}
for
ev
in
scroll_evr
.iter
()
{
match
ev
.unit
{
MouseScrollUnit
::
Line
=>
{
...
...
@@ -148,23 +191,23 @@ pub(crate) fn input_mouse(
/// Handles undo/redo, copy/paste and char input
pub
(
crate
)
fn
input_kb
(
active_editor
:
Res
<
Focus
>
,
// Both
keys
:
Res
<
Input
<
KeyCode
>>
,
// Both
mut
char_evr
:
EventReader
<
ReceivedCharacter
>
,
// Kb
active_editor
:
Res
<
Focus
>
,
keys
:
Res
<
Input
<
KeyCode
>>
,
mut
char_evr
:
EventReader
<
ReceivedCharacter
>
,
mut
cosmic_edit_query
:
Query
<
(
&
mut
CosmicEditor
,
// Both
&
mut
CosmicEditHistory
,
// Kb - Undo
&
CosmicAttrs
,
// Kb - Undo
&
CosmicMaxLines
,
// Kb
&
CosmicMaxChars
,
// Kb
Entity
,
// Both
&
mut
CosmicEditor
,
&
mut
CosmicEditHistory
,
&
CosmicAttrs
,
&
CosmicMaxLines
,
&
CosmicMaxChars
,
Entity
,
Option
<&
ReadOnly
>
,
)
>
,
mut
evw_changed
:
EventWriter
<
CosmicTextChanged
>
,
// Kb
mut
font_system
:
ResMut
<
CosmicFontSystem
>
,
// Both
mut
is_deleting
:
Local
<
bool
>
,
// Kb
mut
edits_duration
:
Local
<
Option
<
Duration
>>
,
// Kb - Undo
mut
undoredo_duration
:
Local
<
Option
<
Duration
>>
,
// Kb - Undo
mut
evw_changed
:
EventWriter
<
CosmicTextChanged
>
,
mut
font_system
:
ResMut
<
CosmicFontSystem
>
,
mut
is_deleting
:
Local
<
bool
>
,
mut
edits_duration
:
Local
<
Option
<
Duration
>>
,
mut
undoredo_duration
:
Local
<
Option
<
Duration
>>
,
)
{
for
(
mut
editor
,
mut
edit_history
,
attrs
,
max_lines
,
max_chars
,
entity
,
readonly_opt
)
in
&
mut
cosmic_edit_query
.iter_mut
()
...
...
@@ -436,13 +479,6 @@ pub(crate) fn input_kb(
}
}
// fix for issue #8
if
let
Some
(
select
)
=
editor
.0
.select_opt
()
{
if
editor
.0
.cursor
()
.line
==
select
.line
&&
editor
.0
.cursor
()
.index
==
select
.index
{
editor
.0
.set_select_opt
(
None
);
}
}
let
mut
is_edit
=
is_clipboard
;
let
mut
is_return
=
false
;
if
keys
.just_pressed
(
KeyCode
::
Return
)
&&
!
readonly
{
...
...
@@ -460,6 +496,14 @@ pub(crate) fn input_kb(
for
char_ev
in
char_evr
.iter
()
{
is_edit
=
true
;
if
*
is_deleting
{
// fix for issue #8
if
let
Some
(
select
)
=
editor
.0
.select_opt
()
{
if
editor
.0
.cursor
()
.line
==
select
.line
&&
editor
.0
.cursor
()
.index
==
select
.index
{
editor
.0
.set_select_opt
(
None
);
}
}
editor
.0
.action
(
&
mut
font_system
.0
,
Action
::
Backspace
);
}
else
if
max_chars
.0
==
0
||
editor
.get_text
()
.len
()
<
max_chars
.0
{
editor
...
...
This diff is collapsed.
Click to expand it.
src/lib.rs
+
2
−
1
View file @
c9eb67b0
...
...
@@ -23,7 +23,7 @@ use cosmic_text::{
use
cursor
::{
change_cursor
,
hover_sprites
,
hover_ui
};
pub
use
cursor
::{
TextHoverIn
,
TextHoverOut
};
use
image
::{
imageops
::
FilterType
,
GenericImageView
};
use
input
::{
input_kb
,
input_mouse
};
use
input
::{
input_kb
,
input_mouse
,
ClickTimer
};
#[derive(Clone,
Component,
PartialEq,
Debug)]
pub
enum
CosmicText
{
...
...
@@ -416,6 +416,7 @@ impl Plugin for CosmicEditPlugin {
swash_cache
:
SwashCache
::
new
(),
})
.insert_resource
(
CosmicFontSystem
(
font_system
))
.insert_resource
(
ClickTimer
(
Timer
::
from_seconds
(
0.5
,
TimerMode
::
Once
)))
.add_event
::
<
CosmicTextChanged
>
();
match
self
.change_cursor
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment