File tree Expand file tree Collapse file tree 3 files changed +46
-3
lines changed
Expand file tree Collapse file tree 3 files changed +46
-3
lines changed Original file line number Diff line number Diff line change @@ -406,6 +406,14 @@ export function deleteLine(): Promise<void> {
406406 return syscall ( "editor.deleteLine" ) ;
407407}
408408
409+ export function moveLineUp ( ) : Promise < void > {
410+ return syscall ( "editor.moveLineUp" ) ;
411+ }
412+
413+ export function moveLineDown ( ) : Promise < void > {
414+ return syscall ( "editor.moveLineDown" ) ;
415+ }
416+
409417// Vim-mode specific syscalls
410418
411419/**
Original file line number Diff line number Diff line change @@ -5,7 +5,15 @@ export async function moveItemUp() {
55 const text = await editor . getText ( ) ;
66
77 try {
8- const currentItemBounds = determineItemBounds ( text , cursorPos ) ;
8+ let currentItemBounds : ReturnType < typeof determineItemBounds > | undefined ;
9+ try {
10+ currentItemBounds = determineItemBounds ( text , cursorPos ) ;
11+ } catch {
12+ // If `determineItemBounds()` throws, that likely means the cursor is NOT in a bullet list,
13+ // so we fall back to `moveLineUp()`
14+ editor . moveLineUp ( ) ;
15+ return ;
16+ }
917 let previousItemBounds : ReturnType < typeof determineItemBounds > | undefined ;
1018
1119 try {
@@ -69,7 +77,15 @@ export async function moveItemDown() {
6977 const text = await editor . getText ( ) ;
7078
7179 try {
72- const currentItemBounds = determineItemBounds ( text , cursorPos ) ;
80+ let currentItemBounds : ReturnType < typeof determineItemBounds > | undefined ;
81+ try {
82+ currentItemBounds = determineItemBounds ( text , cursorPos ) ;
83+ } catch {
84+ // If `determineItemBounds()` throws, that likely means the cursor is NOT in a bullet list,
85+ // so we fall back to `moveLineDown()`
86+ editor . moveLineDown ( ) ;
87+ return ;
88+ }
7389 let nextItemBounds : ReturnType < typeof determineItemBounds > | undefined ;
7490 try {
7591 nextItemBounds = determineItemBounds (
Original file line number Diff line number Diff line change @@ -6,7 +6,14 @@ import {
66 unfoldAll ,
77 unfoldCode ,
88} from "@codemirror/language" ;
9- import { deleteLine , isolateHistory , redo , undo } from "@codemirror/commands" ;
9+ import {
10+ deleteLine ,
11+ isolateHistory ,
12+ moveLineDown ,
13+ moveLineUp ,
14+ redo ,
15+ undo ,
16+ } from "@codemirror/commands" ;
1017import type { Transaction } from "@codemirror/state" ;
1118import { EditorView } from "@codemirror/view" ;
1219import { getCM as vimGetCm , Vim } from "@replit/codemirror-vim" ;
@@ -309,6 +316,18 @@ export function editorSyscalls(client: Client): SysCallMapping {
309316 "editor.deleteLine" : ( ) => {
310317 deleteLine ( client . editorView ) ;
311318 } ,
319+ "editor.moveLineUp" : ( ) => {
320+ return moveLineUp ( {
321+ state : client . editorView . state ,
322+ dispatch : client . editorView . dispatch ,
323+ } ) ;
324+ } ,
325+ "editor.moveLineDown" : ( ) => {
326+ return moveLineDown ( {
327+ state : client . editorView . state ,
328+ dispatch : client . editorView . dispatch ,
329+ } ) ;
330+ } ,
312331 // Folding
313332 "editor.fold" : ( ) => {
314333 foldCode ( client . editorView ) ;
You can’t perform that action at this time.
0 commit comments