From 941699eabd95336a13a57e80c373349ccbf8b634 Mon Sep 17 00:00:00 2001 From: Hiroo Takizawa Date: Thu, 26 Jun 2025 23:22:42 +0900 Subject: [PATCH] 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 --- main.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/main.ts b/main.ts index cdfd785..e3b67c1 100644 --- a/main.ts +++ b/main.ts @@ -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);