@jupyterlab/fileeditor-extension
Advanced tools
Comparing version 0.5.0 to 0.6.0
@@ -10,2 +10,3 @@ "use strict"; | ||
var launcher_1 = require("@jupyterlab/launcher"); | ||
var coreutils_1 = require("@jupyterlab/coreutils"); | ||
/** | ||
@@ -106,2 +107,8 @@ * The class name for the text editor icon from the default theme. | ||
}); | ||
// Update the command registry when the notebook state changes. | ||
tracker.currentChanged.connect(function () { | ||
if (tracker.size <= 1) { | ||
commands.notifyCommandChanged(CommandIDs.lineNumbers); | ||
} | ||
}); | ||
/** | ||
@@ -133,2 +140,16 @@ * Toggle editor line numbers | ||
} | ||
/** To detect if there is no current selection */ | ||
function hasSelection() { | ||
var widget = tracker.currentWidget; | ||
if (!widget) { | ||
return false; | ||
} | ||
var editor = widget.editor; | ||
var selection = editor.getSelection(); | ||
if (selection.start.column === selection.end.column && | ||
selection.start.line === selection.end.line) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
commands.addCommand(CommandIDs.lineNumbers, { | ||
@@ -168,14 +189,29 @@ execute: toggleLineNums, | ||
} | ||
// Get the selected code from the editor. | ||
var code = ""; | ||
var editor = widget.editor; | ||
var selection = editor.getSelection(); | ||
var start = editor.getOffsetAt(selection.start); | ||
var end = editor.getOffsetAt(selection.end); | ||
var targetText = editor.model.value.text.substring(start, end); | ||
if (start == end) { | ||
targetText = editor.getLine(selection.start.line); | ||
var extension = widget.context.path.substring(widget.context.path.lastIndexOf(".")); | ||
if (!hasSelection() && coreutils_1.MarkdownCodeBlocks.isMarkdown(extension)) { | ||
var codeBlocks = coreutils_1.MarkdownCodeBlocks.findMarkdownCodeBlocks(editor.model.value.text); | ||
for (var _i = 0, codeBlocks_1 = codeBlocks; _i < codeBlocks_1.length; _i++) { | ||
var codeBlock = codeBlocks_1[_i]; | ||
if (codeBlock.startLine <= editor.getSelection().start.line && | ||
editor.getSelection().start.line <= codeBlock.endLine) { | ||
code = codeBlock.code; | ||
break; | ||
} | ||
} | ||
} | ||
else { | ||
// Get the selected code from the editor. | ||
var selection = editor.getSelection(); | ||
var start = editor.getOffsetAt(selection.start); | ||
var end = editor.getOffsetAt(selection.end); | ||
code = editor.model.value.text.substring(start, end); | ||
if (start == end) { | ||
code = editor.getLine(selection.start.line); | ||
} | ||
} | ||
var options = { | ||
path: widget.context.path, | ||
code: targetText, | ||
code: code, | ||
activate: false | ||
@@ -182,0 +218,0 @@ }; |
{ | ||
"name": "@jupyterlab/fileeditor-extension", | ||
"version": "0.5.0", | ||
"version": "0.6.0", | ||
"description": "JupyterLab - Editor Widget Extension", | ||
@@ -15,8 +15,9 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@jupyterlab/application": "^0.5.0", | ||
"@jupyterlab/apputils": "^0.5.0", | ||
"@jupyterlab/codeeditor": "^0.5.0", | ||
"@jupyterlab/docregistry": "^0.5.0", | ||
"@jupyterlab/fileeditor": "^0.5.0", | ||
"@jupyterlab/launcher": "^0.5.0" | ||
"@jupyterlab/application": "^0.6.0", | ||
"@jupyterlab/apputils": "^0.6.0", | ||
"@jupyterlab/codeeditor": "^0.6.0", | ||
"@jupyterlab/coreutils": "^0.6.0", | ||
"@jupyterlab/docregistry": "^0.6.0", | ||
"@jupyterlab/fileeditor": "^0.6.0", | ||
"@jupyterlab/launcher": "^0.6.0" | ||
}, | ||
@@ -23,0 +24,0 @@ "devDependencies": { |
9649
243
7
+ Added@jupyterlab/coreutils@^0.6.0
+ Added@jupyterlab/application@0.6.0(transitive)
+ Added@jupyterlab/apputils@0.6.0(transitive)
+ Added@jupyterlab/codeeditor@0.6.0(transitive)
+ Added@jupyterlab/codemirror@0.6.0(transitive)
+ Added@jupyterlab/coreutils@0.6.0(transitive)
+ Added@jupyterlab/docregistry@0.6.0(transitive)
+ Added@jupyterlab/fileeditor@0.6.0(transitive)
+ Added@jupyterlab/launcher@0.6.0(transitive)
+ Added@jupyterlab/services@0.45.0(transitive)
- Removed@jupyterlab/application@0.5.0(transitive)
- Removed@jupyterlab/apputils@0.5.0(transitive)
- Removed@jupyterlab/codeeditor@0.5.0(transitive)
- Removed@jupyterlab/codemirror@0.5.0(transitive)
- Removed@jupyterlab/coreutils@0.5.0(transitive)
- Removed@jupyterlab/docregistry@0.5.0(transitive)
- Removed@jupyterlab/fileeditor@0.5.0(transitive)
- Removed@jupyterlab/launcher@0.5.0(transitive)
- Removed@jupyterlab/services@0.44.0(transitive)
- Removed@types/minimist@1.2.5(transitive)
Updated@jupyterlab/apputils@^0.6.0
Updated@jupyterlab/launcher@^0.6.0