Skip to content

Commit e9bf67b

Browse files
authored
Fix line selection when editor has collapsed lines (#184)
1 parent 974e941 commit e9bf67b

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
# GitLink Changelog
44

55
## [Unreleased]
6+
- Fix line selection around collapsed code sections
67

78
## [4.0.4]
8-
- Add pipeline to handle URL logic
9+
- Add pipeline to handle URL logic
910
- Fix typos
1011

1112
## [4.0.3]

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
pluginGroup = uk.co.ben_gibson.git.link
55
pluginName = GitLink
66
# SemVer format -> https://semver.org
7-
pluginVersion = 4.0.4
7+
pluginVersion = 4.0.5
88

99
# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
1010
# for insight into build numbers and IntelliJ Platform versions.

src/main/kotlin/uk/co/ben_gibson/git/link/ui/EditorExtensions.kt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,20 @@ import com.intellij.openapi.editor.Editor
44

55
val Editor.lineSelection: LineSelection
66
get() {
7-
val primaryCaret = caretModel.primaryCaret
7+
val caretStates = caretModel.caretsAndSelections
88

9-
val start = primaryCaret.selectionStartPosition.line + 1
10-
val end = primaryCaret.selectionEndPosition.line + 1
9+
if (caretStates.size < 1) {
10+
return LineSelection(caretModel.logicalPosition.line + 1)
11+
}
1112

12-
return LineSelection(start, end)
13+
val caretState = caretStates[0]
14+
15+
val start = caretState.selectionStart
16+
val end = caretState.selectionEnd
17+
18+
if (start == null || end == null) {
19+
return LineSelection(caretModel.logicalPosition.line + 1)
20+
}
21+
22+
return LineSelection(start.line + 1, end.line + 1)
1323
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
package uk.co.ben_gibson.git.link.ui
22

3-
data class LineSelection(val start: Int, val end: Int)
3+
data class LineSelection(val start: Int, val end: Int) {
4+
constructor(start: Int) : this(start, start)
5+
}

0 commit comments

Comments
 (0)