fix: compatible with list

This commit is contained in:
Moy 2025-05-09 14:34:46 +08:00
parent 77176c6aad
commit 6b28c8a01b

View file

@ -80,13 +80,23 @@ export default class EasyCopy extends Plugin {
*
*/
private isContinuousText(line: string): boolean {
return line.trim() !== '' && !line.trim().startsWith('#');
// 去除首尾空格后,判断是否为空行、标题行或列表项
return line.trim() !== '' && !line.trim().startsWith('#') && !line.trim().startsWith('- ');
}
/**
* block ID
*/
private detectBlockRange(editor: Editor, cursorLine: number): { start: number, end: number } {
// 如果当前行是列表,那么范围就是当前行(不对,要继续延伸到后面的……只能说开头是定了)
if (editor.getLine(cursorLine).trim().startsWith('- ')) {
let end = cursorLine;
while (end < editor.lineCount() - 1 && this.isContinuousText(editor.getLine(end + 1))) {
end++;
}
return { start: cursorLine, end };
}
const totalLines = editor.lineCount();
let start = cursorLine;
while (start > 0 && this.isContinuousText(editor.getLine(start - 1))) {