13
13
*/
14
14
package org.modelix.editor
15
15
16
- data class CellSelection (val cell : Cell , val downSelection : Selection ? ): Selection() {
16
+ data class CellSelection (val cell : Cell , val directionLeft : Boolean , val previousSelection : Selection ? ): Selection() {
17
17
fun getEditor (): EditorComponent ? = cell.editorComponent
18
18
19
19
override fun isValid (): Boolean {
@@ -23,7 +23,7 @@ data class CellSelection(val cell: Cell, val downSelection: Selection?): Selecti
23
23
override fun update (editor : EditorComponent ): Selection ? {
24
24
return cell.data.cellReferences.asSequence()
25
25
.flatMap { editor.resolveCell(it) }
26
- .map { CellSelection (it, downSelection ?.update(editor)) }
26
+ .map { CellSelection (it, directionLeft, previousSelection ?.update(editor)) }
27
27
.firstOrNull()
28
28
}
29
29
@@ -33,12 +33,38 @@ data class CellSelection(val cell: Cell, val downSelection: Selection?): Selecti
33
33
KnownKeys .ArrowUp -> {
34
34
if (event.modifiers.meta) {
35
35
cell.ancestors().firstOrNull { it.getProperty(CommonCellProperties .selectable) }
36
- ?.let { editor.changeSelection(CellSelection (it, this )) }
36
+ ?.let { editor.changeSelection(CellSelection (it, directionLeft, this )) }
37
37
}
38
38
}
39
39
KnownKeys .ArrowDown -> {
40
- if (event.modifiers.meta && downSelection != null ) {
41
- editor.changeSelection(downSelection)
40
+ if (event.modifiers == Modifiers .META && previousSelection != null ) {
41
+ editor.changeSelection(previousSelection)
42
+ }
43
+ }
44
+ KnownKeys .ArrowLeft , KnownKeys .ArrowRight -> {
45
+ if (event.modifiers == Modifiers .SHIFT ) {
46
+ val isLeft = event.knownKey == KnownKeys .ArrowLeft
47
+ if (isLeft == directionLeft) {
48
+ cell.ancestors().firstOrNull { it.isSelectable() }
49
+ ?.let { editor.changeSelection(CellSelection (it, directionLeft, this )) }
50
+ } else {
51
+ previousSelection?.let { editor.changeSelection(it) }
52
+ }
53
+ } else {
54
+ val caretSelection = generateSequence<Selection >(this ) { (it as ? CellSelection )?.previousSelection }
55
+ .lastOrNull() as ? CaretSelection
56
+ if (caretSelection != null ) {
57
+ editor.changeSelection(CaretSelection (caretSelection.layoutable, caretSelection.start))
58
+ } else {
59
+ val tabTargets = cell.descendantsAndSelf().filter { it.isTabTarget() }
60
+ if (event.knownKey == KnownKeys .ArrowLeft ) {
61
+ tabTargets.firstOrNull()?.layoutable()
62
+ ?.let { editor.changeSelection(CaretSelection (it, 0 )) }
63
+ } else {
64
+ tabTargets.lastOrNull()?.layoutable()
65
+ ?.let { editor.changeSelection(CaretSelection (it, it.cell.getSelectableText()?.length ? : 0 )) }
66
+ }
67
+ }
42
68
}
43
69
}
44
70
else -> {}
0 commit comments