1+ /** @module cursor */
12import { type BaseLine , BaseStore } from "@cosense/types/userscript" ;
23import type { Position } from "./position.ts" ;
34import type { Page } from "./page.d.ts" ;
45
6+ /** Options for setting cursor position
7+ * @interface
8+ */
59export interface SetPositionOptions {
610 /** Whether to auto-scroll the page when the cursor moves outside the viewport
711 *
812 * @default true
13+ * @type {boolean }
914 */
1015 scrollInView ?: boolean ;
1116
1217 /** Source of the cursor movement event
1318 *
1419 * `"mouse"` indicates the cursor was moved by mouse interaction
20+ * @type {"mouse" }
1521 */
1622 source ?: "mouse" ;
1723}
@@ -20,6 +26,7 @@ export interface SetPositionOptions {
2026 *
2127 * @see {@linkcode Position } for cursor position type details
2228 * @see {@linkcode Page } for page data type details
29+ * @extends {@linkcode BaseStore }<{ source: "mouse" | undefined } | "focusTextInput" | "scroll" | undefined>
2330 */
2431export declare class Cursor extends BaseStore <
2532 { source : "mouse" | undefined } | "focusTextInput" | "scroll" | undefined
@@ -31,13 +38,24 @@ export declare class Cursor extends BaseStore<
3138 /** Reset cursor position and remove cursor focus from the editor */
3239 clear ( ) : void ;
3340
34- /** Get the current cursor position */
41+ /** Get the current cursor position
42+ * @returns A {@linkcode Position} containing:
43+ * - Success: The current cursor coordinates and line information
44+ * - Error: Never throws or returns an error
45+ */
3546 getPosition ( ) : Position ;
3647
37- /** Check if the cursor is currently visible */
48+ /** Check if the cursor is currently visible
49+ * @returns A {@linkcode boolean} indicating:
50+ * - Success: `true` if the cursor is visible, `false` otherwise
51+ * - Error: Never throws or returns an error
52+ */
3853 getVisible ( ) : boolean ;
3954
40- /** Move the cursor to the specified position */
55+ /** Move the cursor to the specified position
56+ * @param position - The target position to move the cursor to
57+ * @param option - Optional settings for the cursor movement. See {@linkcode SetPositionOptions}
58+ */
4159 setPosition (
4260 position : Position ,
4361 option ?: SetPositionOptions ,
@@ -67,10 +85,18 @@ export declare class Cursor extends BaseStore<
6785 /** Adjust cursor position to stay within valid line and column boundaries */
6886 fixPosition ( ) : void ;
6987
70- /** Returns `true` if the cursor is visible and at the start of a line */
88+ /** Check if the cursor is at the start of a line
89+ * @returns A {@linkcode boolean} indicating:
90+ * - Success: `true` if the cursor is visible and at line start, `false` otherwise
91+ * - Error: Never throws or returns an error
92+ */
7193 isAtLineHead ( ) : boolean ;
7294
73- /** Returns `true` if the cursor is visible and at the end of a line */
95+ /** Check if the cursor is at the end of a line
96+ * @returns A {@linkcode boolean} indicating:
97+ * - Success: `true` if the cursor is visible and at line end, `false` otherwise
98+ * - Error: Never throws or returns an error
99+ */
74100 isAtLineTail ( ) : boolean ;
75101
76102 /** Make the cursor visible
@@ -87,6 +113,7 @@ export declare class Cursor extends BaseStore<
87113
88114 /** Cursor movement commands
89115 *
116+ * @param action - The movement command to execute. Available commands:
90117 * | Command | Description |
91118 * | ------ | ----------- |
92119 * | go-up | Move cursor up one line |
@@ -122,10 +149,18 @@ export declare class Cursor extends BaseStore<
122149 | "go-pageup" ,
123150 ) : void ;
124151
125- /** Get the content of the current page */
152+ /** Get the content of the current page
153+ * @returns An array of {@linkcode BaseLine} objects containing:
154+ * - Success: The current page's content as an array of line objects
155+ * - Error: Never throws or returns an error
156+ */
126157 get lines ( ) : BaseLine [ ] ;
127158
128- /** Get the current page data */
159+ /** Get the current page data
160+ * @returns A {@linkcode Page} object containing:
161+ * - Success: The current page's metadata and content
162+ * - Error: Never throws or returns an error
163+ */
129164 get page ( ) : Page ;
130165
131166 private goUp ( ) : void ;
@@ -134,7 +169,16 @@ export declare class Cursor extends BaseStore<
134169 private goPageDown ( ) : void ;
135170 private getNextLineHead ( ) : void ;
136171 private getPrevLineTail ( ) : void ;
172+ /** Move cursor backward one character
173+ * @param init - Optional configuration object
174+ * @param init.scrollInView - Whether to scroll the view to keep cursor visible
175+ */
137176 private goBackward ( init ?: { scrollInView : boolean } ) : void ;
177+
178+ /** Move cursor forward one character
179+ * @param init - Optional configuration object
180+ * @param init.scrollInView - Whether to scroll the view to keep cursor visible
181+ */
138182 private goForward ( init ?: { scrollInView : boolean } ) : void ;
139183 private goLeft ( ) : void ;
140184 private goRight ( ) : void ;
@@ -143,8 +187,18 @@ export declare class Cursor extends BaseStore<
143187 /** Jump to the end of the last line */
144188 private goBottom ( ) : void ;
145189 private goWordHead ( ) : void ;
190+ /** Get the position of the next word's start
191+ * @returns A {@linkcode Position} containing:
192+ * - Success: The coordinates and line information of the next word's start
193+ * - Error: Never throws or returns an error
194+ */
146195 private getWordHead ( ) : Position ;
147196 private goWordTail ( ) : void ;
197+ /** Get the position of the previous word's end
198+ * @returns A {@linkcode Position} containing:
199+ * - Success: The coordinates and line information of the previous word's end
200+ * - Error: Never throws or returns an error
201+ */
148202 private getWordTail ( ) : Position ;
149203 /** Jump to the position after indentation
150204 *
0 commit comments