1
0
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:
Sagnik Mandal
2024-03-02 21:28:15 +05:30
committed by GitHub
parent 4c6969b17d
commit d26d9f16d9
10 changed files with 187 additions and 1 deletions

View 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;