Add key action support in multi-edit mode#48
Open
RibosomeK wants to merge 1 commit into
Open
Conversation
…yAction to set currentEntry left and right border, along with chinese translation
Owner
|
@RibosomeK sorry for the late response. We are going to do 2 things here.
Please check the following template. fun getUpdatedEntriesByKeyAction(
action: KeyAction,
appConf: AppConf,
labelerConf: LabelerConf,
): Pair<List<EntryInPixel>, Int>? {
val paramIndex = when (action) {
KeyAction.SetValue1 -> 0
KeyAction.SetValue2 -> 1
KeyAction.SetValue3 -> 2
KeyAction.SetValue4 -> 3
KeyAction.SetValue5 -> 4
KeyAction.SetValue6 -> 5
KeyAction.SetValue7 -> 6
KeyAction.SetValue8 -> 7
KeyAction.SetValue9 -> 8
KeyAction.SetValue10 -> 9
else -> null
}
if (paramIndex != null) {
return getUpdatedEntriesBySetParameterKeyAction(paramIndex, appConf, labelerConf)
}
val isCursorSnapRightSide = when (action) {
KeyAction.SnapClosestLeftParameter -> false
KeyAction.SnapClosestRightParameter -> true
else -> null
}
if (isCursorAction) {
return getUpdatedEntriesByCursorSnapKeyAction(isCursorSnapRightSide, appConf, labelerConf)
}
return null
}
private fun getUpdatedEntriesBySetParameterKeyAction(
paramIndex: Int,
appConf: AppConf,
labelerConf: LabelerConf,
): Pair<List<EntryInPixel>, Int>? {
// remove this -> Only used in single edit mode
// remove this -> if (entries.size != 1) return null
val fieldCount = this.labelerConf.fields.filter { it.shortcutIndex != null }.size
val pointIndex = when {
// TODO: Update the point index supporting multiple entries
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 cursorPosition = cursorState.value.position ?: return null
val lockDrag = appConf.editor.lockedSettingParameterWithCursor &&
when (appConf.editor.lockedDrag) {
AppConf.Editor.LockedDrag.UseLabeler -> {
val lockedDragByBaseField =
labelerConf.lockedDrag.useDragBase &&
labelerConf.fields.getOrNull(pointIndex)?.dragBase == true
val lockedDragByStart =
labelerConf.lockedDrag.useStart && pointIndex == MarkerCursorState.START_POINT_INDEX
lockedDragByBaseField || lockedDragByStart
}
AppConf.Editor.LockedDrag.UseStart -> pointIndex == MarkerCursorState.START_POINT_INDEX
else -> false
}
val entries = if (lockDrag) {
getLockedDraggedEntries(pointIndex, cursorPosition, forcedDrag = false)
// TODO: for multiple mode, we might need to return all `pointIndex`es that are actually affected by the locked drag
// instead of the current `pointIndex`. so we may need to change the function signature, and update corresponding usages of the return value in `fun MarkerState.editEntryIfNeeded` in `Marker.kt`
} else {
getDraggedEntries(pointIndex, cursorPosition, forcedDrag = false)
}
return entries to pointIndex
}
private fun getUpdatedEntriesByCursorSnapKeyAction(
isRightSide: Boolean,
appConf: AppConf,
labelerConf: LabelerConf,
): Pair<List<EntryInPixel>, Int>? {
// TODO: implement this
// can be similar to `getUpdatedEntriesBySetParameterKeyAction` but
// 1. `pointIndex` is decided by the `cursorPosition`
// 2. `lockDrag` is always `false`, because we don't want to move other parameters at the same time here. This is to say, `appConf.editor.lockedSettingParameterWithCursor` should not affect this new feature.
} |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi, in this PR, I add two feature for multi-edit mode, as well as its chinese translation.
First is SetValue1-2 key actions support. Under multi-edit mode, value 1 is the first parameter on the left of the cursor, value 2 is the same but on the right.
The second one is two extra key actions for setting left and right parameter of current entry. But unfortunately, there is bug in getting newest
currentIndexvalue, and I dont't know how to fix that. Can you help me on solving this problem?