diff --git a/src/jvmMain/kotlin/com/sdercolin/vlabeler/model/AppConf.kt b/src/jvmMain/kotlin/com/sdercolin/vlabeler/model/AppConf.kt index 2161f939..9cfbd572 100644 --- a/src/jvmMain/kotlin/com/sdercolin/vlabeler/model/AppConf.kt +++ b/src/jvmMain/kotlin/com/sdercolin/vlabeler/model/AppConf.kt @@ -368,6 +368,7 @@ data class AppConf( val continuousLabelNames: ContinuousLabelNames = ContinuousLabelNames(), val postEditNext: PostEditAction = PostEditAction.DEFAULT_NEXT, val postEditDone: PostEditAction = PostEditAction.DEFAULT_DONE, + val clickToSwitchCurrentIndex: Boolean = DEFAULT_CLICK_TO_SWITCH_CURRENT_INDEX, ) { /** @@ -399,6 +400,7 @@ data class AppConf( const val DEFAULT_SHOW_STAR = true const val DEFAULT_SHOW_TAG = true const val DEFAULT_SHOW_EXTRA = true + const val DEFAULT_CLICK_TO_SWITCH_CURRENT_INDEX = false } } diff --git a/src/jvmMain/kotlin/com/sdercolin/vlabeler/ui/dialog/preferences/PreferencesPages.kt b/src/jvmMain/kotlin/com/sdercolin/vlabeler/ui/dialog/preferences/PreferencesPages.kt index c3b11325..b9475772 100644 --- a/src/jvmMain/kotlin/com/sdercolin/vlabeler/ui/dialog/preferences/PreferencesPages.kt +++ b/src/jvmMain/kotlin/com/sdercolin/vlabeler/ui/dialog/preferences/PreferencesPages.kt @@ -730,6 +730,12 @@ object PreferencesPages { select = { it.playerCursorColor }, update = { copy(playerCursorColor = it) }, ) + switch( + title = Strings.PreferencesEditorClickToJumToEntry, + defaultValue = AppConf.Editor.DEFAULT_CLICK_TO_SWITCH_CURRENT_INDEX, + select = { it.clickToSwitchCurrentIndex }, + update = { copy(clickToSwitchCurrentIndex = it) }, + ) } } } diff --git a/src/jvmMain/kotlin/com/sdercolin/vlabeler/ui/editor/labeler/marker/Marker.kt b/src/jvmMain/kotlin/com/sdercolin/vlabeler/ui/editor/labeler/marker/Marker.kt index 336c0a36..354af980 100644 --- a/src/jvmMain/kotlin/com/sdercolin/vlabeler/ui/editor/labeler/marker/Marker.kt +++ b/src/jvmMain/kotlin/com/sdercolin/vlabeler/ui/editor/labeler/marker/Marker.kt @@ -125,7 +125,15 @@ fun MarkerPointEventContainer( ) } .onPointerEvent(PointerEventType.Press) { event -> - state.handleMousePress(tool, keyboardState, event, state.labelerConf, appState.appConf, screenRange) + state.handleMousePress( + tool, + keyboardState, + event, + state.labelerConf, + appState.appConf, + screenRange, + editorState, + ) } .onPointerEvent(PointerEventType.Release) { event -> state.handleMouseRelease( @@ -583,9 +591,10 @@ private fun MarkerState.handleMousePress( labelerConf: LabelerConf, appConf: AppConf, screenRange: FloatRange?, + editorState: EditorState, ) { when (tool) { - Tool.Cursor -> handleCursorPress(keyboardState, event, labelerConf, appConf) + Tool.Cursor -> handleCursorPress(keyboardState, event, labelerConf, appConf, editorState) Tool.Scissors -> Unit Tool.Pan -> handlePanPress(event) Tool.Playback -> handlePlaybackPress(keyboardState, screenRange, event) @@ -597,6 +606,7 @@ private fun MarkerState.handleCursorPress( event: PointerEvent, labelerConf: LabelerConf, appConf: AppConf, + editorState: EditorState, ) { val action = keyboardState.getEnabledMouseClickAction(event) ?: return if (action.canMoveParameter()) { @@ -619,6 +629,15 @@ private fun MarkerState.handleCursorPress( val forcedDrag = action == MouseClickAction.MoveParameterIgnoringConstraints cursorState.update { startDragging(lockedDrag, withPreview, forcedDrag) } } + if (appConf.editor.clickToSwitchCurrentIndex) { + cursorStateValue.position?.let { position -> + getEntryIndexByCursorPosition(position)?.let { index -> + // having bugs here + // if the cursor do not move, it would not jump + editorState.jumpToEntry(editorState.project.currentModule.name, index) + } + } + } } } diff --git a/src/jvmMain/kotlin/com/sdercolin/vlabeler/ui/editor/labeler/marker/MarkerState.kt b/src/jvmMain/kotlin/com/sdercolin/vlabeler/ui/editor/labeler/marker/MarkerState.kt index dc69498b..115617b5 100644 --- a/src/jvmMain/kotlin/com/sdercolin/vlabeler/ui/editor/labeler/marker/MarkerState.kt +++ b/src/jvmMain/kotlin/com/sdercolin/vlabeler/ui/editor/labeler/marker/MarkerState.kt @@ -415,6 +415,15 @@ class MarkerState( return null } + fun getEntryIndexByCursorPosition(position: Float): Int? { + entriesInPixel.forEachIndexed { index, entry -> + if (entry.getActualStart(labelerConf) <= position && entry.getActualEnd(labelerConf) >= position) { + return index + } + } + return null + } + fun isValidCutPosition(position: Float) = entriesInPixel.any { it.isValidCutPosition(position) } fun isValidPlaybackPosition(position: Float) = position < entryConverter.convertToPixel(sampleLengthMillis) diff --git a/src/jvmMain/kotlin/com/sdercolin/vlabeler/ui/string/Strings.kt b/src/jvmMain/kotlin/com/sdercolin/vlabeler/ui/string/Strings.kt index 023ce4e6..a29a56df 100644 --- a/src/jvmMain/kotlin/com/sdercolin/vlabeler/ui/string/Strings.kt +++ b/src/jvmMain/kotlin/com/sdercolin/vlabeler/ui/string/Strings.kt @@ -397,6 +397,7 @@ enum class Strings { PreferencesEditor, PreferencesEditorDescription, PreferencesEditorPlayerCursorColor, + PreferencesEditorClickToJumToEntry, PreferencesEditorLockedDrag, PreferencesEditorLockedDragDescription, PreferencesEditorLockedDragUseLabeler, diff --git a/src/jvmMain/kotlin/com/sdercolin/vlabeler/ui/string/StringsChineseSimplified.kt b/src/jvmMain/kotlin/com/sdercolin/vlabeler/ui/string/StringsChineseSimplified.kt index fbf5c6cf..0dc00313 100644 --- a/src/jvmMain/kotlin/com/sdercolin/vlabeler/ui/string/StringsChineseSimplified.kt +++ b/src/jvmMain/kotlin/com/sdercolin/vlabeler/ui/string/StringsChineseSimplified.kt @@ -428,6 +428,7 @@ fun Strings.zhHans(): String? = when (this) { PreferencesEditor -> "编辑器" PreferencesEditorDescription -> "编辑编辑器的外观与行为。" PreferencesEditorPlayerCursorColor -> "音频播放光标颜色" + PreferencesEditorClickToJumToEntry -> "在多条目编辑模式下,单击画布上的条目即可跳转到该条目" PreferencesEditorLockedDrag -> "锁定拖动" PreferencesEditorLockedDragDescription -> "选择启用锁定拖动的条件。" + diff --git a/src/jvmMain/kotlin/com/sdercolin/vlabeler/ui/string/StringsEnglish.kt b/src/jvmMain/kotlin/com/sdercolin/vlabeler/ui/string/StringsEnglish.kt index d66bee24..82bc6b72 100644 --- a/src/jvmMain/kotlin/com/sdercolin/vlabeler/ui/string/StringsEnglish.kt +++ b/src/jvmMain/kotlin/com/sdercolin/vlabeler/ui/string/StringsEnglish.kt @@ -474,6 +474,8 @@ fun Strings.en(): String = when (this) { PreferencesEditor -> "Editor" PreferencesEditorDescription -> "Customize the editor's appearance and behavior." PreferencesEditorPlayerCursorColor -> "Player cursor color" + PreferencesEditorClickToJumToEntry -> + "Jump to the cursor position entry by clicking it on canvas in multiple entry edit mode" PreferencesEditorLockedDrag -> "Fixed-drag" PreferencesEditorLockedDragDescription -> "Select a condition to enable fixed-drag while you move " +