Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add border highlight in multi-edit mode #50

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

RibosomeK
Copy link

I add highlight feature and its customization in preferences page. You could highlight the border current entry and cursor position entry in the change. Also, the color and width of the highlight border could be customize.
Currently, if you enable cursor position highlight and try to drag the parameter, it would glitch, jump back and forth between the nearby entry boder. I am sorry that my PRs are full of bugs.

Copy link
Owner

@sdercolin sdercolin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feature is almost done! Thank you very much, it's a very nice idea.

Please check the comments I left.

@@ -313,12 +313,40 @@ private fun FieldBorderCanvas(
state.getEntryIndexesByBorderIndex(pointIndex).second == entryIndex
) 1f else IDLE_LINE_ALPHA
if (border in screenRange) {
var strokeWidth: Float = STROKE_WIDTH
var color = borderColor.copy(alpha = borderLineAlpha)
if (editorConf.highlightCurrentEntryBorder) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add some checks about multiple edit mode here.

}
}
// when dragging, the highlight border would glitch, but I have no idea how to fix that
if (editorConf.highlightCursorPositionEntryBorder) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The most simple fix:

Suggested change
if (editorConf.highlightCursorPositionEntryBorder) {
if (editorConf.highlightCursorPositionEntryBorder &&
cursorState.value.mouse != MarkerCursorState.Mouse.Dragging
) {

But this will cause the highlight to disappear when dragging.

So if we want it perfectly, we need to add a previousPositionBeforeDragging nullable field in MarkerCursorState:

  1. in startDragging, copy the position value to previousPositionBeforeDragging
  2. during dragging, do not change it
  3. in finishDragging, clear it
  4. when drawing the highlight, get the position according to the mouse type. If it's dragging, use previousPositionBeforeDragging, otherwise, use position

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Um, I think I was wrong.
Even if we remember the cursor position before we start dragging, the borders are changing, causing the entry selected also changing.

So we probably should instead remember a relative offset of the clicked position and the parameter line being dragged, so when rendering the lines, we can get a stable cursor position.

Copy link
Owner

@sdercolin sdercolin Nov 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got it working. Please have a look! (It's a git patch, if you don't now how to apply it please Google or GPT)

patch.diff.zip

@@ -488,6 +488,16 @@ fun Strings.zhHans(): String? = when (this) {
PreferencesEditorContinuousLabelNamesEditableBackgroundColor -> "背景色(编辑中)"
PreferencesEditorContinuousLabelNamesSize -> "大小"
PreferencesEditorContinuousLabelNamesPosition -> "位置"
PreferencesEditorBorderHighlight -> "边界高亮"
PreferencesEditorBorderHighlightDescription -> "编辑在多条目编辑模式中边界高亮等的设置"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a period.

updater = { copy(editor = it) },
) {

switch(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use grouping (you can find examples in this file) to make it more clear, and some repeated texts can be simplified.

QQ_1730900533308

For example, these can be simply Color and Width under a group.

Copy link
Owner

@sdercolin sdercolin Nov 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I feel like the default color/width settings should be inverted.
The cursor should have the highest visual priority.

@@ -547,6 +547,18 @@ fun Strings.en(): String = when (this) {
PreferencesEditorContinuousLabelNamesEditableBackgroundColor -> "Background color (editing)"
PreferencesEditorContinuousLabelNamesSize -> "Size"
PreferencesEditorContinuousLabelNamesPosition -> "Position"
PreferencesEditorBorderHighlight -> "Border Highlight"
PreferencesEditorBorderHighlightDescription -> "Customize border highlighting in multiple entry edit mode"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a period.

@sdercolin
Copy link
Owner

sdercolin commented Nov 6, 2024

Ah, for the format error, you can run ./gradlew ktlintFormat gradle task to fix most of them.

@sdercolin sdercolin changed the title add border highlight in multi-edit mode Add border highlight in multi-edit mode Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants