Skip to content

Commit 75cb09c

Browse files
committed
fix types
1 parent 3707320 commit 75cb09c

File tree

5 files changed

+376
-238
lines changed

5 files changed

+376
-238
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
"@codemirror/lang-xml": "^6.0.0",
3939
"@codemirror/language": "^6.1.0",
4040
"codemirror": "6.0.1",
41-
"typescript": "^5.0.2",
42-
"vite": "^2.9.6"
41+
"typescript": "^5.7.3",
42+
"vite": "^6.1.0"
4343
},
4444
"repository": {
4545
"type": "git",

src/cm_adapter.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ export class CodeMirror {
152152
return wordChar.test(ch);
153153
};
154154
static keys: any = keys;
155-
static addClass = function (el, str) { };
156-
static rmClass = function (el, str) { };
155+
static addClass = function (el: any, str: string) { };
156+
static rmClass = function (el: any, str: string) { };
157157
static e_preventDefault = function (e: Event) {
158158
e.preventDefault()
159159
};
@@ -172,7 +172,7 @@ export class CodeMirror {
172172
static signal = signal;
173173

174174
// --------------------------
175-
openDialog(template: Element, callback: Function, options: any) {
175+
openDialog(template: Element, callback: Function|undefined, options: any) {
176176
return openDialog(this, template, callback, options);
177177
};
178178
openNotification(template: Node, options: NotificationOptions) {
@@ -674,7 +674,7 @@ export class CodeMirror {
674674
curOp.cursorActivityHandlers = this._handlers["cursorActivity"] && this._handlers["cursorActivity"].slice();
675675
this.curOp.cursorActivity = true;
676676
};
677-
operation(fn: Function, force?: boolean) {
677+
operation<T>(fn: ()=>T, force?: boolean) {
678678
if (!this.curOp)
679679
this.curOp = { $d: 0 };
680680
this.curOp.$d++;
@@ -727,7 +727,7 @@ export class CodeMirror {
727727

728728
}
729729
};
730-
getOption(name:"firstLineNumber"|"tabSize"): number;
730+
getOption(name:"firstLineNumber"|"tabSize"|"textwidth"): number;
731731
getOption(name:string): number|boolean|string|undefined;
732732
getOption(name: string) {
733733
switch (name) {
@@ -875,7 +875,7 @@ function hideDialog(cm: CodeMirror, dialog: Element) {
875875
}
876876
}
877877

878-
function openDialog(me: CodeMirror, template: Element, callback: Function, options: any) {
878+
function openDialog(me: CodeMirror, template: Element, callback: Function|undefined, options: any) {
879879
if (!options) options = {};
880880

881881
closeNotification(me, undefined);
@@ -913,7 +913,7 @@ function openDialog(me: CodeMirror, template: Element, callback: Function, optio
913913

914914
CodeMirror.on(inp, "keydown", function (e: KeyboardEvent) {
915915
if (options && options.onKeyDown && options.onKeyDown(e, inp.value, close)) { return; }
916-
if (e.keyCode == 13) callback(inp.value);
916+
if (e.keyCode == 13) callback && callback(inp.value);
917917
if (e.keyCode == 27 || (options.closeOnEnter !== false && e.keyCode == 13)) {
918918
inp.blur();
919919
CodeMirror.e_stop(e);
@@ -968,7 +968,8 @@ function scanForBracket(cm: CodeMirror, where: Pos, dir: -1 | 1, style: any, con
968968
return lineNo - dir == (dir > 0 ? cm.lastLine() : cm.firstLine()) ? false : null;
969969
}
970970

971-
function findMatchingTag(cm: CodeMirror, pos: Pos): undefined {
971+
function findMatchingTag(cm: CodeMirror, pos: Pos) {
972+
return null;
972973
}
973974

974975
function findEnclosingTag(cm: CodeMirror, pos: Pos) {
@@ -1029,7 +1030,7 @@ class Marker {
10291030

10301031

10311032

1032-
function hardWrap(cm, options) {
1033+
function hardWrap(cm: CodeMirror, options: {from: number, to: number, column?: number, allowMerge?: boolean}) {
10331034
var max = options.column || cm.getOption('textwidth') || 80;
10341035
var allowMerge = options.allowMerge != false;
10351036

@@ -1066,7 +1067,7 @@ function hardWrap(cm, options) {
10661067
}
10671068
return row;
10681069

1069-
function findSpace(line, max, min) {
1070+
function findSpace(line: string, max: number, min: number) {
10701071
if (line.length < max)
10711072
return;
10721073
var before = line.slice(0, max);

src/types.d.ts

Lines changed: 68 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,19 @@ export type vimState = {
99
marks: {[mark: string]: Marker},
1010
visualMode: boolean,
1111
insertMode: boolean,
12-
pasteFn: any,
13-
lastSelection: any,
14-
searchState_: any,
12+
pasteFn?: any,
13+
lastSelection: {
14+
anchorMark: Marker,
15+
headMark: Marker,
16+
visualLine: boolean,
17+
visualBlock: boolean,
18+
visualMode: boolean,
19+
anchor: Pos,
20+
head: Pos,
21+
},
22+
searchState_?: SearchStateInterface,
1523
lastEditActionCommand: actionCommand|void,
16-
lastPastedText: any,
24+
lastPastedText?: string,
1725
lastMotion: any,
1826
options: {[optionName: string]: vimOption},
1927
lastEditInputState: InputStateInterface|void,
@@ -29,7 +37,6 @@ export type vimState = {
2937
exMode?: boolean,
3038
mode?: any,
3139
expectLiteralNext?: boolean,
32-
constructor(): void;
3340
}
3441
export type Marker = ReturnType<CodeMirror["setBookmark"]>
3542
export type LineHandle = ReturnType<CodeMirror["getLineHandle"]>
@@ -67,7 +74,12 @@ export type OperatorArgs = {
6774
toLower?: boolean,
6875
shouldMoveCursor?: boolean,
6976
selectedCharacter?: string,
70-
lastSel?: any;
77+
lastSel?: {
78+
head: Pos,
79+
anchor: Pos,
80+
visualLine: boolean,
81+
visualBlock: boolean,
82+
},
7183
keepCursor?: boolean;
7284
}
7385
// version of CodeMirror with vim state checked
@@ -173,7 +185,18 @@ export type vimMotions = {
173185
[key: string]: MotionFn
174186
}
175187

176-
188+
export type exCommandDefinition = {
189+
name: string,
190+
shortName?: string,
191+
possiblyAsync?: boolean,
192+
excludeFromCommandHistory?: boolean,
193+
argDelimiter?: string,
194+
type? : string,
195+
toKeys? : string,
196+
toInput?: string,
197+
user?: boolean,
198+
noremap?: boolean,
199+
};
177200

178201
export type optionCallback = (value?: string|undefined, cm?: CodeMirror) => any
179202
export type vimOption = {
@@ -224,7 +247,9 @@ export type operatorMotionCommand = allCommands & {
224247
operator: string,
225248
motionArgs?: MotionArgsPartial,
226249
operatorArgs?: OperatorArgs,
227-
operatorMotionArgs?: { [arg: string]: boolean | string },
250+
operatorMotionArgs?: {
251+
visualLine?: boolean,
252+
},
228253
}
229254
export type idleCommand = allCommands & { type: 'idle' }
230255
export type exCommand = allCommands & { type: 'ex' }
@@ -253,14 +278,36 @@ export interface InputStateInterface {
253278
motionArgs: MotionArgs | null;
254279
keyBuffer: any[];
255280
registerName?: string;
256-
changeQueue: any;
281+
changeQueue: null | { inserted: string, removed: string[]};
257282
operatorShortcut?: string;
258283
selectedCharacter?: string;
259284
repeatOverride?: number;
260285
changeQueueList?: any[];
261286
pushRepeatDigit(n: string): void;
262287
getRepeat(): number;
263288
}
289+
export interface SearchStateInterface {
290+
setReversed(reversed: boolean): void;
291+
isReversed(): boolean|undefined;
292+
getQuery(): RegExp;
293+
setQuery(query: string|RegExp): void;
294+
highlightTimeout: number|undefined;
295+
getOverlay(): {
296+
query: RegExp,
297+
};
298+
getScrollbarAnnotate(): any;
299+
setScrollbarAnnotate(query: RegExp| null): void;
300+
setOverlay(overlay: {query: RegExp}|null): void;
301+
}
302+
303+
export type exCommandArgs = {
304+
callback?: (() => void) | undefined;
305+
input?: string | undefined;
306+
line?: string | undefined;
307+
commandName?: string | undefined;
308+
argString?: string;
309+
args?: string[];
310+
};
264311

265312
export type vimExCommands = {
266313
colorscheme(cm: CodeMirrorV, params: vimExCommandsParams): void,
@@ -302,10 +349,9 @@ type vimExCommandsParams = {
302349
selectionLineEnd?: number
303350
}
304351

305-
306352
export type InsertModeChanges = {
307-
changes: any;
308-
expectCursorActivityForChange: any;
353+
changes: any[];
354+
expectCursorActivityForChange: boolean;
309355
visualBlock?: number,
310356
maybeReset?: boolean,
311357
ignoreCount?: number,
@@ -324,8 +370,17 @@ export type ExParams = {
324370
selectionLineEnd?: number,
325371

326372
setCfg?: Object,
327-
callback?: any,
373+
callback?: () => void,
374+
}
328375

376+
export type PromptOptions = {
377+
onClose?: Function;
378+
prefix: string|HTMLElement;
379+
desc?: string|HTMLElement;
380+
onKeyUp?: Function;
381+
onKeyDown: Function;
382+
value?: string;
383+
selectValueOnOpen?: boolean;
329384
}
330385

331386

0 commit comments

Comments
 (0)