11import { EditorView , Command , Decoration , WidgetType } from "@codemirror/view"
22import { Extension , EditorState } from "@codemirror/state"
3- import { cursorSubwordForward , cursorSubwordBackward , cursorLineDown , cursorLineUp } from "@codemirror/commands"
3+ import { cursorSubwordForward , cursorSubwordBackward , cursorLineDown , cursorLineUp ,
4+ selectLineDown , selectLineUp } from "@codemirror/commands"
45import ist from "ist"
56import { mkState , stateStr } from "./state.js"
67
@@ -20,6 +21,8 @@ function testCmd(before: string, after: string, command: Command, extensions: Ex
2021 }
2122}
2223
24+ const narrow = EditorView . theme ( { "&" : { maxWidth : "13ch" } } )
25+
2326describe ( "commands" , ( ) => {
2427 describe ( "cursorSubwordForward" , ( ) => {
2528 it ( "stops at first camelcase boundary" , ( ) =>
@@ -120,10 +123,8 @@ describe("commands", () => {
120123 } )
121124
122125 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 ] )
126+ testCmd ( "da|ndelion dandelion dandelion" , "dandelion da|ndelion dandelion" ,
127+ cursorLineDown , [ narrow , EditorView . lineWrapping ] )
127128 } )
128129
129130 it ( "isn't affected by folded lines" , ( ) => {
@@ -172,6 +173,18 @@ describe("commands", () => {
172173 cursorLineDown ,
173174 EditorView . decorations . of ( Decoration . set ( Decoration . line ( { attributes} ) . range ( 2 ) ) ) )
174175 } )
176+
177+ it ( "can move in a wrapped line with large line height" , ( ) => {
178+ testCmd ( "da|ndelion dandelion dandelion" ,
179+ "dandelion da|ndelion dandelion" ,
180+ cursorLineDown ,
181+ [ narrow , EditorView . theme ( { ".cm-line" : { lineHeight : "3" } } ) , EditorView . lineWrapping ] )
182+ } )
183+
184+ it ( "keeps assoc when moving through wrapped text" , ( ) => {
185+ testCmd ( "|dandelion dandelion dandelion" , "dandelion dandelion |dandelion" ,
186+ v => cursorLineDown ( v ) && cursorLineDown ( v ) , [ narrow , EditorView . lineWrapping ] )
187+ } )
175188 } )
176189
177190 describe ( "cursorLineUp" , ( ) => {
@@ -192,10 +205,8 @@ describe("commands", () => {
192205 } )
193206
194207 it ( "can move in a wrapped line" , ( ) => {
195- testCmd ( "dandelion dandel|ion dandelion" ,
196- "dandel|ion dandelion dandelion" ,
197- cursorLineUp ,
198- [ EditorView . theme ( { "&" : { maxWidth : "13ch" } } ) , EditorView . lineWrapping ] )
208+ testCmd ( "dandelion dandel|ion dandelion" , "dandel|ion dandelion dandelion" ,
209+ cursorLineUp , [ narrow , EditorView . lineWrapping ] )
199210 } )
200211
201212 it ( "isn't affected by folded lines" , ( ) => {
@@ -229,4 +240,53 @@ describe("commands", () => {
229240 EditorView . decorations . of ( Decoration . set ( Decoration . line ( { attributes} ) . range ( 2 ) ) ) )
230241 } )
231242 } )
243+
244+ describe ( "selectLineDown" , ( ) => {
245+ it ( "selects to the next line" , ( ) => {
246+ testCmd ( "|one\ntwo\nthree" , "<one\n>two\nthree" , selectLineDown )
247+ } )
248+
249+ it ( "keeps the horizontal position" , ( ) => {
250+ testCmd ( "on|e\ntwo\nthree" , "on<e\ntw>o\nthree" , selectLineDown )
251+ } )
252+
253+ it ( "keeps a colum pos across a shorter line" , ( ) => {
254+ testCmd ( "on|e\nt\nthree" , "on<e\nt\nth>ree" , v => selectLineDown ( v ) && selectLineDown ( v ) )
255+ } )
256+
257+ it ( "moves to the end of doc when moving beyond the last line" , ( ) => {
258+ testCmd ( "one\nt|wo" , "one\nt<wo>" , selectLineDown )
259+ } )
260+
261+ it ( "clears goal column when hitting the end of doc" , ( ) => {
262+ testCmd ( "one\ntwo\nth|ree" , "one\ntwo<\nth>ree" , v => selectLineDown ( v ) && selectLineUp ( v ) )
263+ } )
264+
265+ it ( "preserves assoc in wrapped text" , ( ) => {
266+ testCmd ( "|dandelion dandelion dandelion" , "<dandelion dandelion >dandelion" ,
267+ v => selectLineDown ( v ) && selectLineDown ( v ) , [ narrow , EditorView . lineWrapping ] )
268+ } )
269+ } )
270+
271+ describe ( "selectLineUp" , ( ) => {
272+ it ( "selects to the previous line" , ( ) => {
273+ testCmd ( "one\ntwo\n|three" , "one\n<two\n>three" , selectLineUp )
274+ } )
275+
276+ it ( "keeps the horizontal position" , ( ) => {
277+ testCmd ( "one\ntwo\nt|hree" , "one\nt<wo\nt>hree" , selectLineUp )
278+ } )
279+
280+ it ( "keeps a colum pos across a shorter line" , ( ) => {
281+ testCmd ( "one\nt\nthr|ee" , "one<\nt\nthr>ee" , v => selectLineUp ( v ) && selectLineUp ( v ) )
282+ } )
283+
284+ it ( "moves to the start of doc when moving beyond the first line" , ( ) => {
285+ testCmd ( "on|e\ntwo" , "<on>e\ntwo" , selectLineUp )
286+ } )
287+
288+ it ( "clears goal column when hitting the start of doc" , ( ) => {
289+ testCmd ( "on|e\ntwo\nthree" , "on<e\n>two\nthree" , v => selectLineUp ( v ) && selectLineDown ( v ) )
290+ } )
291+ } )
232292} )
0 commit comments