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

Fix incorrect normalising for trailing inlay #558

Merged
merged 1 commit into from
Nov 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class MotionDownActionTest : VimTestCase() {
doTest(keys, before, after, VimStateMachine.Mode.COMMAND, VimStateMachine.SubMode.NONE)
}

fun `test with inlays`() {
fun `test with inlays - move down from line with preceding inlay`() {
val keys = injector.parser.parseKeys("j")
val before = """
I found it in a ${c}legendary land
Expand All @@ -91,7 +91,7 @@ class MotionDownActionTest : VimTestCase() {
assertState(after)
}

fun `test with inlays 2`() {
fun `test with inlays - move down to correct column on line with preceding inlay`() {
val keys = injector.parser.parseKeys("j")
val before = """
I found it in a ${c}legendary land
Expand All @@ -107,7 +107,7 @@ class MotionDownActionTest : VimTestCase() {
assertState(after)
}

fun `test with inlays 3`() {
fun `test with inlays - move down from line with preceding inlay to line with preceding inlay`() {
val keys = injector.parser.parseKeys("j")
val before = """
I found it in a ${c}legendary land
Expand All @@ -124,7 +124,7 @@ class MotionDownActionTest : VimTestCase() {
assertState(after)
}

fun `test with inlays 4`() {
fun `test with inlays - move down from long line with inlay to correct column`() {
val keys = injector.parser.parseKeys("j")
val before = """
I found it in a legendary ${c}land
Expand All @@ -140,7 +140,7 @@ class MotionDownActionTest : VimTestCase() {
assertState(after)
}

fun `test with inlays 5`() {
fun `test with inlays - move down from line with inlay and back to correct column`() {
val keys = injector.parser.parseKeys("jk")
val before = """
I found it in a legendary ${c}land
Expand Down Expand Up @@ -171,7 +171,7 @@ class MotionDownActionTest : VimTestCase() {
assertState(after)
}

fun `test with inlays 6`() {
fun `test with inlays - long line moving onto shorter line with inlay before caret`() {
val keys = injector.parser.parseKeys("j")
val before = """
I found it in a legendary ${c}land
Expand All @@ -187,35 +187,37 @@ class MotionDownActionTest : VimTestCase() {
assertState(after)
}

fun `test with inlays 7`() {
val keys = injector.parser.parseKeys("jk")
fun `test with inlays - long line moving onto shorter line with trailing inlay`() {
val keys = injector.parser.parseKeys("j")
val before = """
I found it in a legendary ${c}land
I found it in a legendary la${c}nd
all rocks and lavender
and tufted grass,
""".trimIndent()
val after = """
I found it in a legendary ${c}land
all rocks and lavender
I found it in a legendary land
all rocks and lavende${c}r
and tufted grass,
""".trimIndent()
configureByText(before)
myFixture.editor.inlayModel.addInlineElement(before.indexOf("rocks"), HintRenderer("Hello"))
val inlayOffset = myFixture.editor.document.getLineEndOffset(1)
myFixture.editor.inlayModel.addInlineElement(inlayOffset, HintRenderer("Hello"))
typeText(keys)
assertState(after)
}

fun `test with inlays 8`() {
val keys = injector.parser.parseKeys("lj")
fun `test with inlays - move down onto line with inlay and back to correct column`() {
val keys = injector.parser.parseKeys("jk")
val before = """
I found it in a ${c}legendary land
all rocks and lavender and tufted grass,
I found it in a legendary ${c}land
all rocks and lavender
""".trimIndent()
val after = """
I found it in a legendary land
all rocks and lav${c}ender and tufted grass,
I found it in a legendary ${c}land
all rocks and lavender
""".trimIndent()
configureByText(before)
myFixture.editor.inlayModel.addInlineElement(before.indexOf("rocks"), HintRenderer("Hello"))
myFixture.editor.inlayModel.addInlineElement(before.indexOf("found"), HintRenderer("Hello"))
typeText(keys)
assertState(after)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,16 @@ abstract class VimMotionGroupBase : VimMotionGroup {
.amountOfInlaysBeforeVisualPosition(editor, VimVisualPosition(line, intendedColumn, false))

val normalisedColumn = editor
.normalizeVisualColumn(line, intendedColumn, editor.isEndAllowed)
val adjustedColumn = normalisedColumn + additionalVisualColumns
.normalizeVisualColumn(line, intendedColumn + additionalVisualColumns, editor.isEndAllowed)

val newPos = VimVisualPosition(line, adjustedColumn, false)
val newPos = VimVisualPosition(line, intendedColumn + additionalVisualColumns, false)
val offset = editor.visualPositionToOffset(newPos).point
return if (intendedColumn != adjustedColumn) {
offset.toAdjustedMotionOrError(intendedColumn)
val bufferLine = editor.offsetToBufferPosition(offset).line
val normalisedOffset = editor.normalizeOffset(bufferLine, offset, editor.isEndAllowed)
return if (intendedColumn != normalisedColumn) {
normalisedOffset.toAdjustedMotionOrError(intendedColumn)
} else {
offset.toMotionOrError()
normalisedOffset.toMotionOrError()
}
}

Expand Down