Add support for numbered list cursor positioning with Home key

- Add detection for numbered lists (1. 2. etc.) in move-cursor-after-bullet command
- Implement moveCursorAfterNumberedList function to position cursor after number and dot
- Supports indented numbered lists with proper whitespace handling
This commit is contained in:
Hiroo Takizawa 2025-06-26 23:22:42 +09:00
parent 04d8f466b1
commit 941699eabd

28
main.ts
View file

@ -41,6 +41,9 @@ export default class AutoBulletPlugin extends Plugin {
// If this is a bullet point line, move the cursor after the bullet (- )
if (line.trim().startsWith('- ')) {
this.moveCursorAfterBullet(editor);
} else if (/^\s*\d+\.\s/.test(line)) {
// If this is a numbered list, move the cursor after the number and dot
this.moveCursorAfterNumberedList(editor);
} else {
// For normal lines, move cursor to the beginning of the line (similar to standard Ctrl+A behavior)
editor.setCursor({ line: cursor.line, ch: 0 });
@ -82,6 +85,31 @@ export default class AutoBulletPlugin extends Plugin {
return false;
}
// Function to move cursor after numbered list
moveCursorAfterNumberedList(editor: Editor) {
try {
const cursor = editor.getCursor();
const line = editor.getLine(cursor.line);
// Check if the line is a numbered list
const match = line.match(/^(\s*)(\d+\.\s)/);
if (match) {
const indentLength = match[1].length;
const numberPartLength = match[2].length;
const targetPosition = indentLength + numberPartLength;
// Move cursor only if it's not already at the target position
if (cursor.ch !== targetPosition) {
editor.setCursor({ line: cursor.line, ch: targetPosition });
return true;
}
}
} catch (error) {
console.error(`Error in moveCursorAfterNumberedList: ${error.message}`);
}
return false;
}
private handleEditorChange = (editor: Editor) => {
const cursor = editor.getCursor();
const line = editor.getLine(cursor.line);