Add killLine method

This commit is contained in:
Tal Wrii 2025-02-26 02:55:44 +01:00
parent 233737089f
commit 6605ea90ff

View file

@ -289,6 +289,10 @@ export default class ReplPlugin extends Plugin {
"kill", kill.bind(null, editor),
"(start: Position, end: Position) Delete the region between start and end"
)
this.addToScopeWithDoc(
"killLine", killLine.bind(null, editor),
"Delete the current line"
)
this.addToScopeWithDoc(
"lineAtPoint", lineAtPoint.bind(null, editor),
"Return the content of the line where the cursor is. Optionally takes a cursor position as an argument"
@ -531,6 +535,13 @@ function kill(editor: Editor, pos1?: EditorPosition, pos2?: EditorPosition) {
}
function killLine(editor: Editor) {
const cursor = editor.getCursor()
const line = editor.getLine(cursor.line)
editor.replaceRange("", { ...cursor, ch: 0 }, { ...cursor, ch: line.length })
}