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
b07bf690
Commit
b07bf690
authored
1 year ago
by
sam edelsten
Browse files
Options
Downloads
Patches
Plain Diff
pause cursor blink on input
parent
74e22f18
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/lib.rs
+52
-11
52 additions, 11 deletions
src/lib.rs
with
52 additions
and
11 deletions
src/lib.rs
+
52
−
11
View file @
b07bf690
...
...
@@ -399,11 +399,17 @@ impl Plugin for CosmicEditPlugin {
.before
(
on_scale_factor_change
),
cosmic_edit_redraw_buffer
.before
(
on_scale_factor_change
),
blink_cursor
,
freeze_cursor_blink
,
hide_inactive_cursor
,
clear_inactive_selection
,
),
)
.init_resource
::
<
Focus
>
()
.insert_resource
(
CursorBlinkTimer
(
Timer
::
from_seconds
(
0.53
,
TimerMode
::
Repeating
,
)))
.insert_resource
(
CursorVisibility
(
true
))
.insert_resource
(
SwashCacheState
{
swash_cache
:
SwashCache
::
new
(),
})
...
...
@@ -1293,32 +1299,35 @@ fn cosmic_edit_redraw_buffer_ui(
}
}
#[derive(Resource)]
struct
CursorBlinkTimer
(
pub
Timer
);
#[derive(Resource)]
struct
CursorVisibility
(
pub
bool
);
fn
blink_cursor
(
mut
visib
le
:
Local
<
bool
>
,
mut
timer
:
Local
<
Option
<
Timer
>
>
,
mut
visib
ility
:
ResMut
<
CursorVisibility
>
,
mut
timer
:
ResMut
<
CursorBlink
Timer
>
,
time
:
Res
<
Time
>
,
active_editor
:
ResMut
<
Focus
>
,
mut
cosmic_editor_q
:
Query
<&
mut
CosmicEditor
,
Without
<
ReadOnly
>>
,
)
{
if
let
Some
(
e
)
=
active_editor
.0
{
if
let
Ok
(
mut
editor
)
=
cosmic_editor_q
.get_mut
(
e
)
{
let
timer
=
timer
.get_or_insert_with
(||
Timer
::
from_seconds
(
0.53
,
TimerMode
::
Repeating
));
timer
.tick
(
time
.delta
());
if
!
timer
.just_finished
()
&&
!
active_editor
.is_changed
()
{
timer
.0
.tick
(
time
.delta
());
if
!
timer
.0
.just_finished
()
&&
!
active_editor
.is_changed
()
{
return
;
}
*
visib
le
=
!
*
visib
le
;
visib
ility
.0
=
!
visib
ility
.0
;
// always start cursor visible on focus
if
active_editor
.is_changed
()
{
*
visib
le
=
true
;
timer
.set_elapsed
(
Duration
::
from_secs
(
0
)
);
visib
ility
.0
=
true
;
timer
.
0
.
set_elapsed
(
Duration
::
ZERO
);
}
let
mut
cursor
=
editor
.0
.cursor
();
let
new_color
=
if
*
visib
le
{
let
new_color
=
if
visib
ility
.0
{
None
}
else
{
Some
(
cosmic_text
::
Color
::
rgba
(
0
,
0
,
0
,
0
))
...
...
@@ -1330,6 +1339,38 @@ fn blink_cursor(
}
}
fn
freeze_cursor_blink
(
mut
visibility
:
ResMut
<
CursorVisibility
>
,
mut
timer
:
ResMut
<
CursorBlinkTimer
>
,
active_editor
:
Res
<
Focus
>
,
keys
:
Res
<
Input
<
KeyCode
>>
,
char_evr
:
EventReader
<
ReceivedCharacter
>
,
mut
editor_q
:
Query
<&
mut
CosmicEditor
>
,
)
{
let
inputs
=
[
KeyCode
::
Left
,
KeyCode
::
Right
,
KeyCode
::
Up
,
KeyCode
::
Down
,
KeyCode
::
Back
,
KeyCode
::
Return
,
];
if
!
keys
.any_pressed
(
inputs
)
&&
char_evr
.is_empty
()
{
return
;
}
if
let
Some
(
e
)
=
active_editor
.0
{
if
let
Ok
(
mut
editor
)
=
editor_q
.get_mut
(
e
)
{
timer
.0
.set_elapsed
(
Duration
::
ZERO
);
visibility
.0
=
true
;
let
mut
cursor
=
editor
.0
.cursor
();
cursor
.color
=
None
;
editor
.0
.set_cursor
(
cursor
);
editor
.0
.buffer_mut
()
.set_redraw
(
true
);
}
}
}
fn
hide_inactive_cursor
(
mut
cosmic_editor_q
:
Query
<
(
Entity
,
&
mut
CosmicEditor
)
>
,
active_editor
:
Res
<
Focus
>
,
...
...
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