You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-07-13 00:10:37 +02:00
Desktop: Fixes #10007: Fixed Toggle Comment & Delete/Duplicate/Sort Line Options in Beta Editor (#10016)
This commit is contained in:
34
packages/editor/CodeMirror/editorCommands/duplicateLine.ts
Normal file
34
packages/editor/CodeMirror/editorCommands/duplicateLine.ts
Normal file
@ -0,0 +1,34 @@
|
||||
import { EditorSelection } from '@codemirror/state';
|
||||
import { Command, EditorView } from '@codemirror/view';
|
||||
|
||||
const duplicateLine: Command = (editor: EditorView) => {
|
||||
const state = editor.state;
|
||||
const doc = state.doc;
|
||||
|
||||
const transaction = state.changeByRange(range => {
|
||||
const currentLine = doc.lineAt(range.anchor);
|
||||
|
||||
let text, insertPos, selectionRange;
|
||||
if (range.empty) {
|
||||
text = `\n${currentLine.text}`;
|
||||
insertPos = currentLine.to;
|
||||
selectionRange = EditorSelection.cursor(currentLine.to + text.length);
|
||||
} else {
|
||||
text = doc.slice(range.from, range.to);
|
||||
insertPos = range.to;
|
||||
selectionRange = EditorSelection.range(range.to, range.to + text.length);
|
||||
}
|
||||
return {
|
||||
range: selectionRange,
|
||||
changes: [{
|
||||
from: insertPos,
|
||||
to: insertPos,
|
||||
insert: text,
|
||||
}],
|
||||
};
|
||||
});
|
||||
|
||||
editor.dispatch(transaction);
|
||||
return true;
|
||||
};
|
||||
export default duplicateLine;
|
Reference in New Issue
Block a user