-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use edit way can actually affect the created time-tag type indication. merge.
- Loading branch information
1 parent
d126d1c
commit b6a81be
Showing
2 changed files
with
34 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System; | ||
using osu.Framework.Allocation; | ||
using osu.Framework.Bindables; | ||
using osu.Framework.Graphics.Sprites; | ||
|
@@ -22,9 +21,7 @@ public partial class CreateTimeTagActionSection : EditorSection, IKeyBindingHand | |
[Resolved] | ||
private ILyricTimeTagsChangeHandler lyricTimeTagsChangeHandler { get; set; } = null!; | ||
|
||
[Resolved] | ||
private ILyricCaretState lyricCaretState { get; set; } = null!; | ||
|
||
private readonly IBindable<ICaretPosition?> bindableCaretPosition = new Bindable<ICaretPosition?>(); | ||
private readonly Bindable<CreateTimeTagType> bindableCreateType = new(); | ||
|
||
public CreateTimeTagActionSection() | ||
|
@@ -39,43 +36,53 @@ public CreateTimeTagActionSection() | |
} | ||
|
||
[BackgroundDependencyLoader] | ||
private void load(IEditTimeTagModeState editTimeTagModeState) | ||
private void load(IEditTimeTagModeState editTimeTagModeState, ILyricCaretState lyricCaretState) | ||
{ | ||
bindableCaretPosition.BindTo(lyricCaretState.BindableCaretPosition); | ||
bindableCreateType.BindTo(editTimeTagModeState.BindableCreateType); | ||
} | ||
|
||
public bool OnPressed(KeyBindingPressEvent<KaraokeEditAction> e) | ||
{ | ||
var action = e.Action; | ||
var caretPosition = lyricCaretState.CaretPosition; | ||
var caretPosition = bindableCaretPosition.Value; | ||
|
||
if (caretPosition is not CreateRemoveTimeTagCaretPosition createRemoveTimeTagCaretPosition) | ||
return false; | ||
|
||
return caretPosition switch | ||
if (LyricEditor.ToMovingCaretAction(e.Action) != null) | ||
{ | ||
CreateRemoveTimeTagCaretPosition timeTagIndexCaretPosition => processCreateTimeTagAction(timeTagIndexCaretPosition, action), | ||
_ => throw new NotSupportedException(nameof(caretPosition)), | ||
}; | ||
bindableCreateType.Value = CreateTimeTagType.Keyboard; | ||
return false; | ||
} | ||
|
||
if (createTimeTagByKeyboard(createRemoveTimeTagCaretPosition.CharIndex, action)) | ||
{ | ||
bindableCreateType.Value = CreateTimeTagType.Keyboard; | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
private bool processCreateTimeTagAction(CreateRemoveTimeTagCaretPosition createRemoveTimeTagCaretPosition, KaraokeEditAction action) | ||
private bool createTimeTagByKeyboard(int charIndex, KaraokeEditAction action) | ||
{ | ||
int index = createRemoveTimeTagCaretPosition.CharIndex; | ||
|
||
switch (action) | ||
{ | ||
case KaraokeEditAction.CreateStartTimeTag: | ||
lyricTimeTagsChangeHandler.AddByPosition(new TextIndex(index)); | ||
lyricTimeTagsChangeHandler.AddByPosition(new TextIndex(charIndex)); | ||
return true; | ||
|
||
case KaraokeEditAction.CreateEndTimeTag: | ||
lyricTimeTagsChangeHandler.AddByPosition(new TextIndex(index, TextIndex.IndexState.End)); | ||
lyricTimeTagsChangeHandler.AddByPosition(new TextIndex(charIndex, TextIndex.IndexState.End)); | ||
return true; | ||
|
||
case KaraokeEditAction.RemoveStartTimeTag: | ||
lyricTimeTagsChangeHandler.RemoveByPosition(new TextIndex(index)); | ||
lyricTimeTagsChangeHandler.RemoveByPosition(new TextIndex(charIndex)); | ||
return true; | ||
|
||
case KaraokeEditAction.RemoveEndTimeTag: | ||
lyricTimeTagsChangeHandler.RemoveByPosition(new TextIndex(index, TextIndex.IndexState.End)); | ||
lyricTimeTagsChangeHandler.RemoveByPosition(new TextIndex(charIndex, TextIndex.IndexState.End)); | ||
return true; | ||
|
||
default: | ||
|