parent
6f4b02298c
commit
411416fe65
|
@ -406,6 +406,14 @@ export function deleteLine(): Promise<void> {
|
|||
return syscall("editor.deleteLine");
|
||||
}
|
||||
|
||||
export function moveLineUp(): Promise<void> {
|
||||
return syscall("editor.moveLineUp");
|
||||
}
|
||||
|
||||
export function moveLineDown(): Promise<void> {
|
||||
return syscall("editor.moveLineDown");
|
||||
}
|
||||
|
||||
// Vim-mode specific syscalls
|
||||
|
||||
/**
|
||||
|
|
|
@ -5,7 +5,15 @@ export async function moveItemUp() {
|
|||
const text = await editor.getText();
|
||||
|
||||
try {
|
||||
const currentItemBounds = determineItemBounds(text, cursorPos);
|
||||
let currentItemBounds: ReturnType<typeof determineItemBounds> | undefined;
|
||||
try {
|
||||
currentItemBounds = determineItemBounds(text, cursorPos);
|
||||
} catch {
|
||||
// If `determineItemBounds()` throws, that likely means the cursor is NOT in a bullet list,
|
||||
// so we fall back to `moveLineUp()`
|
||||
editor.moveLineUp();
|
||||
return;
|
||||
}
|
||||
let previousItemBounds: ReturnType<typeof determineItemBounds> | undefined;
|
||||
|
||||
try {
|
||||
|
@ -69,7 +77,15 @@ export async function moveItemDown() {
|
|||
const text = await editor.getText();
|
||||
|
||||
try {
|
||||
const currentItemBounds = determineItemBounds(text, cursorPos);
|
||||
let currentItemBounds: ReturnType<typeof determineItemBounds> | undefined;
|
||||
try {
|
||||
currentItemBounds = determineItemBounds(text, cursorPos);
|
||||
} catch {
|
||||
// If `determineItemBounds()` throws, that likely means the cursor is NOT in a bullet list,
|
||||
// so we fall back to `moveLineDown()`
|
||||
editor.moveLineDown();
|
||||
return;
|
||||
}
|
||||
let nextItemBounds: ReturnType<typeof determineItemBounds> | undefined;
|
||||
try {
|
||||
nextItemBounds = determineItemBounds(
|
||||
|
|
|
@ -6,7 +6,14 @@ import {
|
|||
unfoldAll,
|
||||
unfoldCode,
|
||||
} from "@codemirror/language";
|
||||
import { deleteLine, isolateHistory, redo, undo } from "@codemirror/commands";
|
||||
import {
|
||||
deleteLine,
|
||||
isolateHistory,
|
||||
moveLineDown,
|
||||
moveLineUp,
|
||||
redo,
|
||||
undo,
|
||||
} from "@codemirror/commands";
|
||||
import type { Transaction } from "@codemirror/state";
|
||||
import { EditorView } from "@codemirror/view";
|
||||
import { getCM as vimGetCm, Vim } from "@replit/codemirror-vim";
|
||||
|
@ -309,6 +316,18 @@ export function editorSyscalls(client: Client): SysCallMapping {
|
|||
"editor.deleteLine": () => {
|
||||
deleteLine(client.editorView);
|
||||
},
|
||||
"editor.moveLineUp": () => {
|
||||
return moveLineUp({
|
||||
state: client.editorView.state,
|
||||
dispatch: client.editorView.dispatch,
|
||||
});
|
||||
},
|
||||
"editor.moveLineDown": () => {
|
||||
return moveLineDown({
|
||||
state: client.editorView.state,
|
||||
dispatch: client.editorView.dispatch,
|
||||
});
|
||||
},
|
||||
// Folding
|
||||
"editor.fold": () => {
|
||||
foldCode(client.editorView);
|
||||
|
|
Loading…
Reference in New Issue