Skip to content

Commit

Permalink
Merge pull request #5795 from aschlaep/ctrl-f-init
Browse files Browse the repository at this point in the history
Add ctrl-f/g support for notebooks and text files
  • Loading branch information
jasongrout committed Feb 1, 2019
2 parents 7636581 + 31e0484 commit 937a3d8
Show file tree
Hide file tree
Showing 34 changed files with 2,094 additions and 1,462 deletions.
3 changes: 3 additions & 0 deletions dev_mode/package.json
Expand Up @@ -31,6 +31,7 @@
"@jupyterlab/docmanager": "^0.19.1",
"@jupyterlab/docmanager-extension": "^0.19.1",
"@jupyterlab/docregistry": "^0.19.1",
"@jupyterlab/documentsearch-extension": "^0.19.1",
"@jupyterlab/extensionmanager": "^0.19.1",
"@jupyterlab/extensionmanager-extension": "^0.19.1",
"@jupyterlab/faq-extension": "^0.19.1",
Expand Down Expand Up @@ -147,6 +148,7 @@
"@jupyterlab/console-extension": "",
"@jupyterlab/csvviewer-extension": "",
"@jupyterlab/docmanager-extension": "",
"@jupyterlab/documentsearch-extension": "",
"@jupyterlab/extensionmanager-extension": "",
"@jupyterlab/faq-extension": "",
"@jupyterlab/filebrowser-extension": "",
Expand Down Expand Up @@ -251,6 +253,7 @@
"@jupyterlab/docmanager": "../packages/docmanager",
"@jupyterlab/docmanager-extension": "../packages/docmanager-extension",
"@jupyterlab/docregistry": "../packages/docregistry",
"@jupyterlab/documentsearch-extension": "../packages/documentsearch-extension",
"@jupyterlab/extensionmanager": "../packages/extensionmanager",
"@jupyterlab/extensionmanager-extension": "../packages/extensionmanager-extension",
"@jupyterlab/faq-extension": "../packages/faq-extension",
Expand Down
2 changes: 1 addition & 1 deletion examples/console/package.json
Expand Up @@ -18,7 +18,7 @@
"es6-promise": "~4.1.1"
},
"devDependencies": {
"@types/codemirror": "~0.0.46",
"@types/codemirror": "~0.0.70",
"css-loader": "~0.28.7",
"file-loader": "~1.1.11",
"mini-css-extract-plugin": "~0.4.4",
Expand Down
2 changes: 1 addition & 1 deletion examples/filebrowser/package.json
Expand Up @@ -22,7 +22,7 @@
"es6-promise": "~4.1.1"
},
"devDependencies": {
"@types/codemirror": "~0.0.46",
"@types/codemirror": "~0.0.70",
"css-loader": "~0.28.7",
"file-loader": "~1.1.11",
"mini-css-extract-plugin": "~0.4.4",
Expand Down
2 changes: 1 addition & 1 deletion examples/notebook/package.json
Expand Up @@ -22,7 +22,7 @@
"es6-promise": "~4.1.1"
},
"devDependencies": {
"@types/codemirror": "~0.0.46",
"@types/codemirror": "~0.0.70",
"css-loader": "~0.28.7",
"file-loader": "~1.1.11",
"mini-css-extract-plugin": "~0.4.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/codemirror/package.json
Expand Up @@ -46,7 +46,7 @@
"react": "~16.4.2"
},
"devDependencies": {
"@types/codemirror": "~0.0.46",
"@types/codemirror": "~0.0.70",
"rimraf": "~2.6.2",
"typedoc": "~0.12.0",
"typescript": "~3.1.1"
Expand Down
76 changes: 65 additions & 11 deletions packages/codemirror/src/editor.ts
@@ -1,5 +1,7 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
/// <reference types="codemirror"/>
/// <reference types="codemirror/searchcursor"/>

import CodeMirror from 'codemirror';

Expand Down Expand Up @@ -377,6 +379,65 @@ export class CodeMirrorEditor implements CodeEditor.IEditor {
this._clearHover();
}

// todo: docs, maybe define overlay options as a type?
addOverlay(mode: string | object, options?: object): void {
this._editor.addOverlay(mode, options);
}

removeOverlay(mode: string | object): void {
this._editor.removeOverlay(mode);
}

getSearchCursor(
query: string | RegExp,
start?: CodeMirror.Position,
caseFold?: boolean
): CodeMirror.SearchCursor {
return this._editor.getDoc().getSearchCursor(query, start, caseFold);
}

getCursor(start?: string): CodeMirror.Position {
return this._editor.getDoc().getCursor(start);
}

get state(): any {
return this._editor.state;
}

operation<T>(fn: () => T): T {
return this._editor.operation(fn);
}

firstLine(): number {
return this._editor.getDoc().firstLine();
}

lastLine(): number {
return this._editor.getDoc().lastLine();
}

scrollIntoView(
pos: { from: CodeMirror.Position; to: CodeMirror.Position },
margin: number
): void {
this._editor.scrollIntoView(pos, margin);
}

cursorCoords(
where: boolean,
mode?: 'window' | 'page' | 'local'
): { left: number; top: number; bottom: number } {
return this._editor.cursorCoords(where, mode);
}

getRange(
from: CodeMirror.Position,
to: CodeMirror.Position,
seperator?: string
): string {
return this._editor.getDoc().getRange(from, to, seperator);
}

/**
* Add a keydown handler to the editor.
*
Expand Down Expand Up @@ -415,7 +476,10 @@ export class CodeMirrorEditor implements CodeEditor.IEditor {
* Reveal the given selection in the editor.
*/
revealSelection(selection: CodeEditor.IRange): void {
const range = this._toCodeMirrorRange(selection);
const range = {
from: this._toCodeMirrorPosition(selection.start),
to: this._toCodeMirrorPosition(selection.end)
};
this._editor.scrollIntoView(range);
}

Expand Down Expand Up @@ -763,16 +827,6 @@ export class CodeMirrorEditor implements CodeEditor.IEditor {
};
}

/**
* Converts an editor selection to a code mirror selection.
*/
private _toCodeMirrorRange(range: CodeEditor.IRange): CodeMirror.Range {
return {
from: this._toCodeMirrorPosition(range.start),
to: this._toCodeMirrorPosition(range.end)
};
}

/**
* Convert a code mirror position to an editor position.
*/
Expand Down
1 change: 1 addition & 0 deletions packages/codemirror/src/typings.d.ts
Expand Up @@ -2,3 +2,4 @@
// Distributed under the terms of the Modified BSD License.

/// <reference path="../typings/codemirror/codemirror.d.ts"/>
/// <reference types="@types/codemirror/searchcursor"/>

0 comments on commit 937a3d8

Please sign in to comment.