From f65c1063960cccb4f4b04485e71b1d53d3df57e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gonzalo=20Rodr=C3=ADguez?= <13141462+gonzarodriguezt@users.noreply.github.com> Date: Wed, 2 Oct 2019 17:16:35 -0400 Subject: [PATCH] Add getValue/setValue to CodeMirror.Editor (#38381) --- types/codemirror/index.d.ts | 14 ++++++++++++-- types/codemirror/test/index.ts | 4 ++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/types/codemirror/index.d.ts b/types/codemirror/index.d.ts index 4fecc3687b..6d3622e82f 100644 --- a/types/codemirror/index.d.ts +++ b/types/codemirror/index.d.ts @@ -220,6 +220,16 @@ declare namespace CodeMirror { /** Set the content of the current editor document. */ setValue(content: string): void; + /** start is a an optional string indicating which end of the selection to return. + It may be "from", "to", "head" (the side of the selection that moves when you press shift+arrow), + or "anchor" (the fixed side of the selection).Omitting the argument is the same as passing "head". A {line, ch} object will be returned. **/ + getCursor(start?: string): CodeMirror.Position; + + /** Set the cursor position. You can either pass a single {line, ch} object, or the line and the character as two separate parameters. + Will replace all selections with a single, empty selection at the given position. + The supported options are the same as for setSelection */ + setCursor(pos: CodeMirror.Position | number, ch?: number, options?: { bias?: number, origin?: string, scroll?: boolean }): void; + /** Sets the gutter marker for the given gutter (identified by its CSS class, see the gutters option) to the given value. Value can be either null, to clear the marker, or a DOM element, to set it. The DOM element will be shown in the specified gutter next to the specified line. */ setGutterMarker(line: any, gutterID: string, value: HTMLElement | null): CodeMirror.LineHandle; @@ -577,8 +587,8 @@ declare namespace CodeMirror { replaceSelection(replacement: string, collapse?: string): void; /** start is a an optional string indicating which end of the selection to return. - It may be "start" , "end" , "head"(the side of the selection that moves when you press shift + arrow), - or "anchor"(the fixed side of the selection).Omitting the argument is the same as passing "head".A { line , ch } object will be returned. */ + It may be "from", "to", "head" (the side of the selection that moves when you press shift+arrow), + or "anchor" (the fixed side of the selection).Omitting the argument is the same as passing "head". A {line, ch} object will be returned. **/ getCursor(start?: string): CodeMirror.Position; /** Retrieves a list of all current selections. These will always be sorted, and never overlap (overlapping selections are merged). diff --git a/types/codemirror/test/index.ts b/types/codemirror/test/index.ts index 8c1a860e31..958ae15d55 100644 --- a/types/codemirror/test/index.ts +++ b/types/codemirror/test/index.ts @@ -73,6 +73,10 @@ myCodeMirror.getValue(); myCodeMirror.getValue("foo") myCodeMirror.setValue("bar"); +myCodeMirror.getCursor(); +myCodeMirror.getCursor('from'); +myCodeMirror.setCursor({ ch: 1, line: 0 }); + myCodeMirror.on( "renderLine", (instance: CodeMirror.Editor, line: CodeMirror.LineHandle, element: HTMLElement) => { }