diff --git a/src/jvmMain/kotlin/com/sdercolin/vlabeler/model/action/KeyAction.kt b/src/jvmMain/kotlin/com/sdercolin/vlabeler/model/action/KeyAction.kt index 8f203b3a..9baeefb2 100644 --- a/src/jvmMain/kotlin/com/sdercolin/vlabeler/model/action/KeyAction.kt +++ b/src/jvmMain/kotlin/com/sdercolin/vlabeler/model/action/KeyAction.kt @@ -410,6 +410,8 @@ enum class KeyAction( KeySet(Key.P), false, ), + SetCurrentEntryLeft(listOf(Strings.ActionSetCurrentEntryLeft), null, false), + SetCurrentEntryRight(listOf(Strings.ActionSetCurrentEntryRight), null, false), SetProperty1(listOf(Strings.ActionSetProperty1), null, false), SetProperty2(listOf(Strings.ActionSetProperty2), null, false), SetProperty3(listOf(Strings.ActionSetProperty3), null, false), 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..cbf2be5c 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 @@ -44,6 +44,7 @@ class MarkerState( val canvasHeightState: MutableState, val waveformsHeightRatio: Float, private val snapDrag: SnapDrag, + val currentIndex: MutableState, ) { val entryBorders: List = entriesInPixel.fold>(listOf()) { acc, entryInPixel -> val lastEntryEnd = acc.lastOrNull() @@ -415,6 +416,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) @@ -448,21 +458,41 @@ class MarkerState( KeyAction.SetValue8 -> 7 KeyAction.SetValue9 -> 8 KeyAction.SetValue10 -> 9 + KeyAction.SetCurrentEntryLeft -> 0 + KeyAction.SetCurrentEntryRight -> 1 else -> return null } - // Only used in single edit mode - if (entries.size != 1) return null - - val fieldCount = this.labelerConf.fields.filter { it.shortcutIndex != null }.size - val pointIndex = when { - paramIndex == 0 -> MarkerCursorState.START_POINT_INDEX - paramIndex == fieldCount + 1 -> MarkerCursorState.END_POINT_INDEX - paramIndex <= fieldCount -> this.labelerConf.fields.indexOfFirst { it.shortcutIndex == paramIndex } - .takeIf { it >= 0 } ?: return null - else -> return null - } + val pointIndex: Int? val cursorPosition = cursorState.value.position ?: return null + if (entries.size != 1) { + // filedCount might be wrong + // and would not work on potential variant fields like dv label + val fieldCount = this.labelerConf.fields.filter { it.shortcutIndex != null }.size + val index = if (action == KeyAction.SetCurrentEntryLeft || action == KeyAction.SetCurrentEntryRight) { + currentIndex.value + } else { + getEntryIndexByCursorPosition(cursorPosition) ?: return null + } + pointIndex = when { + paramIndex == 0 -> if (index == 0) MarkerCursorState.START_POINT_INDEX else index * (fieldCount + 1) - 1 + paramIndex == fieldCount + 1 -> + if (index == entries.size - 1) MarkerCursorState.END_POINT_INDEX else index * (fieldCount + 1) + paramIndex <= fieldCount -> this.labelerConf.fields.indexOfFirst { it.shortcutIndex == paramIndex } + .takeIf { it > 0 }?.plus(index * (fieldCount + 1)) ?: return null + else -> return null + } + } else { + val fieldCount = this.labelerConf.fields.filter { it.shortcutIndex != null }.size + pointIndex = when { + paramIndex == 0 -> MarkerCursorState.START_POINT_INDEX + paramIndex == fieldCount + 1 -> MarkerCursorState.END_POINT_INDEX + paramIndex <= fieldCount -> this.labelerConf.fields.indexOfFirst { it.shortcutIndex == paramIndex } + .takeIf { it >= 0 } ?: return null + else -> return null + } + } + val lockDrag = appConf.editor.lockedSettingParameterWithCursor && when (appConf.editor.lockedDrag) { AppConf.Editor.LockedDrag.UseLabeler -> { @@ -571,6 +601,7 @@ fun rememberMarkerState( entryConverter, ) } + val currentIndex = mutableStateOf(project.currentModule.currentIndex) return remember( sampleRate, @@ -608,6 +639,7 @@ fun rememberMarkerState( canvasHeightState, waveformsHeightRatio, snapDrag, + currentIndex ) } } 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..fd411d81 100644 --- a/src/jvmMain/kotlin/com/sdercolin/vlabeler/ui/string/Strings.kt +++ b/src/jvmMain/kotlin/com/sdercolin/vlabeler/ui/string/Strings.kt @@ -514,6 +514,8 @@ enum class Strings { ActionSetValue8, ActionSetValue9, ActionSetValue10, + ActionSetCurrentEntryLeft, + ActionSetCurrentEntryRight, ActionSetProperty1, ActionSetProperty2, ActionSetProperty3, 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..0d37f037 100644 --- a/src/jvmMain/kotlin/com/sdercolin/vlabeler/ui/string/StringsChineseSimplified.kt +++ b/src/jvmMain/kotlin/com/sdercolin/vlabeler/ui/string/StringsChineseSimplified.kt @@ -553,8 +553,8 @@ fun Strings.zhHans(): String? = when (this) { ActionInputResolution -> "输入画布分辨率" ActionCancelDialog -> "关闭对话框" ActionScissorsCut -> "在当前光标位置切割" - ActionSetValue1 -> "将参数1设置到光标位置" - ActionSetValue2 -> "将参数2设置到光标位置" + ActionSetValue1 -> "将参数1设置到光标位置(多条目编辑模式下为光标位置左边第一条参数)" + ActionSetValue2 -> "将参数2设置到光标位置(多条目编辑模式下为光标位置右边第一条参数)" ActionSetValue3 -> "将参数3设置到光标位置" ActionSetValue4 -> "将参数4设置到光标位置" ActionSetValue5 -> "将参数5设置到光标位置" @@ -563,6 +563,8 @@ fun Strings.zhHans(): String? = when (this) { ActionSetValue8 -> "将参数8设置到光标位置" ActionSetValue9 -> "将参数9设置到光标位置" ActionSetValue10 -> "将参数10设置到光标位置" + ActionSetCurrentEntryLeft -> "多条目编辑模式下,将当前条目的左边界设置到光标位置" + ActionSetCurrentEntryRight -> "多条目编辑模式下,将当前条目的右边界设置到光标位置" ActionSetProperty1 -> "输入属性1的值" ActionSetProperty2 -> "输入属性2的值" ActionSetProperty3 -> "输入属性3的值" 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..651b05a0 100644 --- a/src/jvmMain/kotlin/com/sdercolin/vlabeler/ui/string/StringsEnglish.kt +++ b/src/jvmMain/kotlin/com/sdercolin/vlabeler/ui/string/StringsEnglish.kt @@ -618,8 +618,8 @@ fun Strings.en(): String = when (this) { ActionInputResolution -> "Input Canvas Resolution" ActionCancelDialog -> "Close Dialog" ActionScissorsCut -> "Cut at Current Cursor Position" - ActionSetValue1 -> "Set Parameter 1 To Cursor Position" - ActionSetValue2 -> "Set Parameter 2 To Cursor Position" + ActionSetValue1 -> "Set Parameter 1 To Cursor Position (Start Parameter In Multiple Entry Edit Mode)" + ActionSetValue2 -> "Set Parameter 2 To Cursor Position (End Parameter In Multiple Entry Edit Mode)" ActionSetValue3 -> "Set Parameter 3 To Cursor Position" ActionSetValue4 -> "Set Parameter 4 To Cursor Position" ActionSetValue5 -> "Set Parameter 5 To Cursor Position" @@ -628,6 +628,8 @@ fun Strings.en(): String = when (this) { ActionSetValue8 -> "Set Parameter 8 To Cursor Position" ActionSetValue9 -> "Set Parameter 9 To Cursor Position" ActionSetValue10 -> "Set Parameter 10 To Cursor Position" + ActionSetCurrentEntryLeft -> "Set Current Entry Left Parameter To Cursor Position In Multiple Entry Edit Mode" + ActionSetCurrentEntryRight -> "Set Current Entry Right Parameter To Cursor Position In Multiple Entry Edit Mode" ActionSetProperty1 -> "Input Value for Property 1" ActionSetProperty2 -> "Input Value for Property 2" ActionSetProperty3 -> "Input Value for Property 3"