|
1 | | -import {EditorView, Command} from "@codemirror/view" |
| 1 | +import {EditorView, Command, Decoration, WidgetType} from "@codemirror/view" |
2 | 2 | import {Extension, EditorState} from "@codemirror/state" |
3 | | -import {cursorSubwordForward, cursorSubwordBackward} from "@codemirror/commands" |
| 3 | +import {cursorSubwordForward, cursorSubwordBackward, cursorLineDown, cursorLineUp} from "@codemirror/commands" |
4 | 4 | import ist from "ist" |
5 | 5 | import {mkState, stateStr} from "./state.js" |
6 | 6 |
|
@@ -97,4 +97,106 @@ describe("commands", () => { |
97 | 97 | }) |
98 | 98 | } |
99 | 99 | }) |
| 100 | + |
| 101 | + let w = new class extends WidgetType { |
| 102 | + toDOM() { let d = document.createElement("div"); d.style.cssText = "color: blue; height: 4em"; return d } |
| 103 | + } |
| 104 | + |
| 105 | + describe("cursorLineDown", () => { |
| 106 | + it("can move to the next line", () => { |
| 107 | + testCmd("on|e\ntwo", "one\ntw|o", cursorLineDown) |
| 108 | + }) |
| 109 | + |
| 110 | + it("can move to a shorter line", () => { |
| 111 | + testCmd("on|e\nt", "one\nt|", cursorLineDown) |
| 112 | + }) |
| 113 | + |
| 114 | + it("goes to the end on last line", () => { |
| 115 | + testCmd("on|e", "one|", cursorLineDown) |
| 116 | + }) |
| 117 | + |
| 118 | + it("keeps a colum pos across a shorter line", () => { |
| 119 | + testCmd("on|e\nt\nthree", "one\nt\nth|ree", v => { cursorLineDown(v); cursorLineDown(v); return true }) |
| 120 | + }) |
| 121 | + |
| 122 | + it("can move in a wrapped line", () => { |
| 123 | + testCmd("da|ndelion dandelion dandelion", |
| 124 | + "dandelion da|ndelion dandelion", |
| 125 | + cursorLineDown, |
| 126 | + [EditorView.theme({"&": {maxWidth: "13ch"}}), EditorView.lineWrapping]) |
| 127 | + }) |
| 128 | + |
| 129 | + it("isn't affected by folded lines", () => { |
| 130 | + testCmd("on|e two\nthree four\nfive six\nseven eight", |
| 131 | + "one two\nthree four\nfive six\nse|ven eight", |
| 132 | + cursorLineDown, |
| 133 | + EditorView.decorations.of(Decoration.set(Decoration.replace({}).range(5, 26)))) |
| 134 | + }) |
| 135 | + |
| 136 | + it("skips block widgets", () => { |
| 137 | + testCmd("on|e\ntwo\nthree\nfour", |
| 138 | + "one\ntwo\nthree\nfo|ur", |
| 139 | + cursorLineDown, |
| 140 | + EditorView.decorations.of(Decoration.set(Decoration.replace({widget: w, block: true}).range(4, 13)))) |
| 141 | + }) |
| 142 | + |
| 143 | + it("skips multiple block widgets", () => { |
| 144 | + testCmd("on|e\ntwo\nthree\nfour", |
| 145 | + "one\ntwo\nthree\nfo|ur", |
| 146 | + cursorLineDown, |
| 147 | + EditorView.decorations.of(Decoration.set([ |
| 148 | + Decoration.replace({widget: w, block: true}).range(4, 7), |
| 149 | + Decoration.replace({widget: w, block: true}).range(8, 13) |
| 150 | + ]))) |
| 151 | + }) |
| 152 | + }) |
| 153 | + |
| 154 | + describe("cursorLineUp", () => { |
| 155 | + it("can move to the previous line", () => { |
| 156 | + testCmd("one\ntwo|", "one|\ntwo", cursorLineUp) |
| 157 | + }) |
| 158 | + |
| 159 | + it("can move to a shorter line", () => { |
| 160 | + testCmd("o\ntwo|", "o|\ntwo", cursorLineUp) |
| 161 | + }) |
| 162 | + |
| 163 | + it("goes to the start on first line", () => { |
| 164 | + testCmd("on|e", "|one", cursorLineUp) |
| 165 | + }) |
| 166 | + |
| 167 | + it("keeps a colum pos across a shorter line", () => { |
| 168 | + testCmd("one\nt\nthr|ee", "one|\nt\nthree", v => { cursorLineUp(v); cursorLineUp(v); return true }) |
| 169 | + }) |
| 170 | + |
| 171 | + it("can move in a wrapped line", () => { |
| 172 | + testCmd("dandelion dandel|ion dandelion", |
| 173 | + "dandel|ion dandelion dandelion", |
| 174 | + cursorLineUp, |
| 175 | + [EditorView.theme({"&": {maxWidth: "13ch"}}), EditorView.lineWrapping]) |
| 176 | + }) |
| 177 | + |
| 178 | + it("isn't affected by folded lines", () => { |
| 179 | + testCmd("one two\nthree four\nfive six\ns|even eight", |
| 180 | + "o|ne two\nthree four\nfive six\nseven eight", |
| 181 | + cursorLineUp, |
| 182 | + EditorView.decorations.of(Decoration.set(Decoration.replace({}).range(5, 26)))) |
| 183 | + }) |
| 184 | + |
| 185 | + it("skips block widgets", () => { |
| 186 | + testCmd("one\ntwo\nthree\n|four", |
| 187 | + "|one\ntwo\nthree\nfour", |
| 188 | + cursorLineUp, |
| 189 | + EditorView.decorations.of(Decoration.set(Decoration.replace({widget: w, block: true}).range(4, 13)))) |
| 190 | + }) |
| 191 | + |
| 192 | + it("skips multiple block widgets", () => { |
| 193 | + testCmd("one\ntwo\nthree\nfo|ur", |
| 194 | + "on|e\ntwo\nthree\nfour", |
| 195 | + cursorLineUp, |
| 196 | + EditorView.decorations.of(Decoration.set([ |
| 197 | + Decoration.replace({widget: w, block: true}).range(4, 7), |
| 198 | + Decoration.replace({widget: w, block: true}).range(8, 13) |
| 199 | + ]))) |
| 200 | + }) |
| 201 | + }) |
100 | 202 | }) |
0 commit comments