Skip to content

Commit fbc1e45

Browse files
authored
fix(codemirror): fix selection update event types and others (DefinitelyTyped#44502)
* fix(codemirror): fix selection update event types and others * fix(codemirror): type fix in match highlighter addon * feat(codemirror): add missing properties and function to EditorConfiguration and Doc interfaces
1 parent 526c36a commit fbc1e45

File tree

2 files changed

+31
-31
lines changed

2 files changed

+31
-31
lines changed

types/codemirror/addon/search/match-highlighter.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ declare module 'codemirror' {
3030
showToken?: boolean | RegExp;
3131

3232
/**
33-
* Used to specify how much time to wait, in milliseconds, before highlighting the matches.
33+
* Used to specify how much time to wait, in milliseconds, before highlighting the matches (default is 100).
3434
*/
35-
delay: 100;
35+
delay?: number,
3636

3737
/**
3838
* If wordsOnly is enabled, the matches will be highlighted only if the selected text is a word.

types/codemirror/index.d.ts

+29-29
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// ysulyma <https://github.com/ysulyma>
99
// azoson <https://github.com/azoson>
1010
// kylesferrazza <https://github.com/kylesferrazza>
11+
// fityocsaba96 <https://github.com/fityocsaba96>
1112
// koddsson <https://github.com/koddsson>
1213
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
1314
// TypeScript Version: 3.2
@@ -112,16 +113,8 @@ declare namespace CodeMirror {
112113
function off(doc: Doc, eventName: 'cursorActivity', handler: (instance: CodeMirror.Editor) => void): void;
113114

114115
/** Equivalent to the event by the same name as fired on editor instances. */
115-
function on(
116-
doc: Doc,
117-
eventName: 'beforeSelectionChange',
118-
handler: (instance: CodeMirror.Editor, selection: { head: Position; anchor: Position }) => void,
119-
): void;
120-
function off(
121-
doc: Doc,
122-
eventName: 'beforeSelectionChange',
123-
handler: (instance: CodeMirror.Editor, selection: { head: Position; anchor: Position }) => void,
124-
): void;
116+
function on(doc: Doc, eventName: 'beforeSelectionChange', handler: (instance: CodeMirror.Editor, obj: EditorSelectionChange) => void ): void;
117+
function off(doc: Doc, eventName: 'beforeSelectionChange', handler: (instance: CodeMirror.Editor, obj: EditorSelectionChange) => void ): void;
125118

126119
/** Will be fired when the line object is deleted. A line object is associated with the start of the line.
127120
Mostly useful when you need to find out when your gutter markers on a given line are removed. */
@@ -467,6 +460,9 @@ declare namespace CodeMirror {
467460
/** Tells you whether the editor's content can be edited by the user. */
468461
isReadOnly(): boolean;
469462

463+
/** Returns the preferred line separator string for this document, as per the option by the same name. When that option is null, the string "\n" is returned. */
464+
lineSeparator(): string;
465+
470466
/** Switches between overwrite and normal insert mode (when not given an argument),
471467
or sets the overwrite mode to a specific state (when given an argument). */
472468
toggleOverwrite(value?: boolean): void;
@@ -550,20 +546,8 @@ declare namespace CodeMirror {
550546

551547
/** This event is fired before the selection is moved. Its handler may modify the resulting selection head and anchor.
552548
Handlers for this event have the same restriction as "beforeChange" handlers they should not do anything to directly update the state of the editor. */
553-
on(
554-
eventName: 'beforeSelectionChange',
555-
handler: (
556-
instance: CodeMirror.Editor,
557-
selection: { head: CodeMirror.Position; anchor: CodeMirror.Position },
558-
) => void,
559-
): void;
560-
off(
561-
eventName: 'beforeSelectionChange',
562-
handler: (
563-
instance: CodeMirror.Editor,
564-
selection: { head: CodeMirror.Position; anchor: CodeMirror.Position },
565-
) => void,
566-
): void;
549+
on(eventName: 'beforeSelectionChange', handler: (instance: CodeMirror.Editor, obj: EditorSelectionChange) => void ): void;
550+
off(eventName: 'beforeSelectionChange', handler: (instance: CodeMirror.Editor, obj: EditorSelectionChange) => void ): void;
567551

568552
/** Fires whenever the view port of the editor changes (due to scrolling, editing, or any other factor).
569553
The from and to arguments give the new start and end of the viewport. */
@@ -706,7 +690,7 @@ declare namespace CodeMirror {
706690

707691
/** Replace the part of the document between from and to with the given string.
708692
from and to must be {line, ch} objects. to can be left off to simply insert the string at position from. */
709-
replaceRange(replacement: string, from: CodeMirror.Position, to?: CodeMirror.Position, origin?: string): void;
693+
replaceRange(replacement: string | string[], from: CodeMirror.Position, to?: CodeMirror.Position, origin?: string): void;
710694

711695
/** Get the content of line n. */
712696
getLine(n: number): string;
@@ -774,7 +758,7 @@ declare namespace CodeMirror {
774758

775759
/** Retrieves a list of all current selections. These will always be sorted, and never overlap (overlapping selections are merged).
776760
Each object in the array contains anchor and head properties referring to {line, ch} objects. */
777-
listSelections(): { anchor: CodeMirror.Position; head: CodeMirror.Position }[];
761+
listSelections(): Range[];
778762

779763
/** Return true if any text is selected. */
780764
somethingSelected(): boolean;
@@ -976,11 +960,11 @@ declare namespace CodeMirror {
976960
above?: boolean;
977961
/** When true, will cause the widget to be rendered even if the line it is associated with is hidden. */
978962
showIfHidden?: boolean;
979-
/** Determines whether the editor will capture mouse and drag events occurring in this widget.
963+
/** Determines whether the editor will capture mouse and drag events occurring in this widget.
980964
Default is false—the events will be left alone for the default browser handler, or specific handlers on the widget, to capture. */
981965
handleMouseEvents?: boolean;
982-
/** By default, the widget is added below other widgets for the line.
983-
This option can be used to place it at a different position (zero for the top, N to put it after the Nth other widget).
966+
/** By default, the widget is added below other widgets for the line.
967+
This option can be used to place it at a different position (zero for the top, N to put it after the Nth other widget).
984968
Note that this only has effect once, when the widget is created. */
985969
insertAt?: number;
986970
/** Add an extra CSS class name to the wrapper element created for the widget. */
@@ -1018,11 +1002,18 @@ declare namespace CodeMirror {
10181002
(line: number, ch?: number, sticky?: string): Position;
10191003
}
10201004

1005+
interface EditorSelectionChange {
1006+
ranges: Range[];
1007+
update(ranges: Range[]): void;
1008+
origin?: string;
1009+
}
1010+
10211011
interface Range {
10221012
anchor: CodeMirror.Position;
10231013
head: CodeMirror.Position;
10241014
from(): CodeMirror.Position;
10251015
to(): CodeMirror.Position;
1016+
empty(): boolean;
10261017
}
10271018

10281019
interface Position {
@@ -1125,12 +1116,21 @@ declare namespace CodeMirror {
11251116
/** boolean|string. This disables editing of the editor content by the user. If the special value "nocursor" is given (instead of simply true), focusing of the editor is also disallowed. */
11261117
readOnly?: any;
11271118

1119+
/** This label is read by the screenreaders when CodeMirror text area is focused. This is helpful for accessibility. */
1120+
screenReaderLabel?: string;
1121+
11281122
/**Whether the cursor should be drawn when a selection is active. Defaults to false. */
11291123
showCursorWhenSelecting?: boolean;
11301124

11311125
/** When enabled, which is the default, doing copy or cut when there is no selection will copy or cut the whole lines that have cursors on them. */
11321126
lineWiseCopyCut?: boolean;
11331127

1128+
/** When pasting something from an external source (not from the editor itself), if the number of lines matches the number of selection, CodeMirror will by default insert one line per selection. You can set this to false to disable that behavior. */
1129+
pasteLinesPerSelection?: boolean;
1130+
1131+
/** Determines whether multiple selections are joined as soon as they touch (the default) or only when they overlap (true). */
1132+
selectionsMayTouch?: boolean;
1133+
11341134
/** The maximum number of undo levels that the editor stores. Defaults to 40. */
11351135
undoDepth?: number;
11361136

0 commit comments

Comments
 (0)