@codemirror/commands
Advanced tools
Comparing version 0.19.4 to 0.19.5
@@ -0,1 +1,7 @@ | ||
## 0.19.5 (2021-09-21) | ||
### New features | ||
Adds an `insertBlankLine` command which creates an empty line below the selection, and binds it to Mod-Enter in the default keymap. | ||
## 0.19.4 (2021-09-13) | ||
@@ -2,0 +8,0 @@ |
@@ -297,2 +297,6 @@ import { StateCommand } from '@codemirror/state'; | ||
/** | ||
Create a blank, indented line below the current line. | ||
*/ | ||
declare const insertBlankLine: StateCommand; | ||
/** | ||
Auto-indent the selected lines. This uses the [indentation service | ||
@@ -386,2 +390,3 @@ facet](https://codemirror.net/6/docs/ref/#language.indentService) as source for auto-indent | ||
- Escape: [`simplifySelection`](https://codemirror.net/6/docs/ref/#commands.simplifySelection) | ||
- Ctrl-Enter (Comd-Enter on macOS): [`insertBlankLine`](https://codemirror.net/6/docs/ref/#commands.insertBlankLine) | ||
- Alt-l (Ctrl-l on macOS): [`selectLine`](https://codemirror.net/6/docs/ref/#commands.selectLine) | ||
@@ -404,2 +409,2 @@ - Ctrl-i (Cmd-i on macOS): [`selectParentSyntax`](https://codemirror.net/6/docs/ref/#commands.selectParentSyntax) | ||
export { copyLineDown, copyLineUp, cursorCharBackward, cursorCharForward, cursorCharLeft, cursorCharRight, cursorDocEnd, cursorDocStart, cursorGroupBackward, cursorGroupForward, cursorGroupLeft, cursorGroupRight, cursorLineBoundaryBackward, cursorLineBoundaryForward, cursorLineDown, cursorLineEnd, cursorLineStart, cursorLineUp, cursorMatchingBracket, cursorPageDown, cursorPageUp, cursorSubwordBackward, cursorSubwordForward, cursorSyntaxLeft, cursorSyntaxRight, defaultKeymap, deleteCharBackward, deleteCharForward, deleteGroupBackward, deleteGroupForward, deleteLine, deleteToLineEnd, deleteToLineStart, deleteTrailingWhitespace, emacsStyleKeymap, indentLess, indentMore, indentSelection, indentWithTab, insertNewline, insertNewlineAndIndent, insertTab, moveLineDown, moveLineUp, selectAll, selectCharBackward, selectCharForward, selectCharLeft, selectCharRight, selectDocEnd, selectDocStart, selectGroupBackward, selectGroupForward, selectGroupLeft, selectGroupRight, selectLine, selectLineBoundaryBackward, selectLineBoundaryForward, selectLineDown, selectLineEnd, selectLineStart, selectLineUp, selectMatchingBracket, selectPageDown, selectPageUp, selectParentSyntax, selectSubwordBackward, selectSubwordForward, selectSyntaxLeft, selectSyntaxRight, simplifySelection, splitLine, standardKeymap, transposeChars }; | ||
export { copyLineDown, copyLineUp, cursorCharBackward, cursorCharForward, cursorCharLeft, cursorCharRight, cursorDocEnd, cursorDocStart, cursorGroupBackward, cursorGroupForward, cursorGroupLeft, cursorGroupRight, cursorLineBoundaryBackward, cursorLineBoundaryForward, cursorLineDown, cursorLineEnd, cursorLineStart, cursorLineUp, cursorMatchingBracket, cursorPageDown, cursorPageUp, cursorSubwordBackward, cursorSubwordForward, cursorSyntaxLeft, cursorSyntaxRight, defaultKeymap, deleteCharBackward, deleteCharForward, deleteGroupBackward, deleteGroupForward, deleteLine, deleteToLineEnd, deleteToLineStart, deleteTrailingWhitespace, emacsStyleKeymap, indentLess, indentMore, indentSelection, indentWithTab, insertBlankLine, insertNewline, insertNewlineAndIndent, insertTab, moveLineDown, moveLineUp, selectAll, selectCharBackward, selectCharForward, selectCharLeft, selectCharRight, selectDocEnd, selectDocStart, selectGroupBackward, selectGroupForward, selectGroupLeft, selectGroupRight, selectLine, selectLineBoundaryBackward, selectLineBoundaryForward, selectLineDown, selectLineEnd, selectLineStart, selectLineUp, selectMatchingBracket, selectPageDown, selectPageUp, selectParentSyntax, selectSubwordBackward, selectSubwordForward, selectSyntaxLeft, selectSyntaxRight, simplifySelection, splitLine, standardKeymap, transposeChars }; |
@@ -705,27 +705,36 @@ import { EditorSelection, CharCategory } from '@codemirror/state'; | ||
*/ | ||
const insertNewlineAndIndent = ({ state, dispatch }) => { | ||
if (state.readOnly) | ||
return false; | ||
let changes = state.changeByRange(({ from, to }) => { | ||
let explode = from == to && isBetweenBrackets(state, from); | ||
let cx = new IndentContext(state, { simulateBreak: from, simulateDoubleBreak: !!explode }); | ||
let indent = getIndentation(cx, from); | ||
if (indent == null) | ||
indent = /^\s*/.exec(state.doc.lineAt(from).text)[0].length; | ||
let line = state.doc.lineAt(from); | ||
while (to < line.to && /\s/.test(line.text[to - line.from])) | ||
to++; | ||
if (explode) | ||
({ from, to } = explode); | ||
else if (from > line.from && from < line.from + 100 && !/\S/.test(line.text.slice(0, from))) | ||
from = line.from; | ||
let insert = ["", indentString(state, indent)]; | ||
if (explode) | ||
insert.push(indentString(state, cx.lineIndent(line.from, -1))); | ||
return { changes: { from, to, insert: Text.of(insert) }, | ||
range: EditorSelection.cursor(from + 1 + insert[1].length) }; | ||
}); | ||
dispatch(state.update(changes, { scrollIntoView: true, userEvent: "input" })); | ||
return true; | ||
}; | ||
const insertNewlineAndIndent = /*@__PURE__*/newlineAndIndent(false); | ||
/** | ||
Create a blank, indented line below the current line. | ||
*/ | ||
const insertBlankLine = /*@__PURE__*/newlineAndIndent(true); | ||
function newlineAndIndent(atEof) { | ||
return ({ state, dispatch }) => { | ||
if (state.readOnly) | ||
return false; | ||
let changes = state.changeByRange(range => { | ||
let { from, to } = range, line = state.doc.lineAt(from); | ||
let explode = !atEof && from == to && isBetweenBrackets(state, from); | ||
if (atEof) | ||
from = to = (to <= line.to ? line : state.doc.lineAt(to)).to; | ||
let cx = new IndentContext(state, { simulateBreak: from, simulateDoubleBreak: !!explode }); | ||
let indent = getIndentation(cx, from); | ||
if (indent == null) | ||
indent = /^\s*/.exec(state.doc.lineAt(from).text)[0].length; | ||
while (to < line.to && /\s/.test(line.text[to - line.from])) | ||
to++; | ||
if (explode) | ||
({ from, to } = explode); | ||
else if (from > line.from && from < line.from + 100 && !/\S/.test(line.text.slice(0, from))) | ||
from = line.from; | ||
let insert = ["", indentString(state, indent)]; | ||
if (explode) | ||
insert.push(indentString(state, cx.lineIndent(line.from, -1))); | ||
return { changes: { from, to, insert: Text.of(insert) }, | ||
range: EditorSelection.cursor(from + 1 + insert[1].length) }; | ||
}); | ||
dispatch(state.update(changes, { scrollIntoView: true, userEvent: "input" })); | ||
return true; | ||
}; | ||
} | ||
function changeBySelectedLine(state, f) { | ||
@@ -931,2 +940,3 @@ let atLine = -1; | ||
- Escape: [`simplifySelection`](https://codemirror.net/6/docs/ref/#commands.simplifySelection) | ||
- Ctrl-Enter (Comd-Enter on macOS): [`insertBlankLine`](https://codemirror.net/6/docs/ref/#commands.insertBlankLine) | ||
- Alt-l (Ctrl-l on macOS): [`selectLine`](https://codemirror.net/6/docs/ref/#commands.selectLine) | ||
@@ -948,2 +958,3 @@ - Ctrl-i (Cmd-i on macOS): [`selectParentSyntax`](https://codemirror.net/6/docs/ref/#commands.selectParentSyntax) | ||
{ key: "Escape", run: simplifySelection }, | ||
{ key: "Mod-Enter", run: insertBlankLine }, | ||
{ key: "Alt-l", mac: "Ctrl-l", run: selectLine }, | ||
@@ -965,2 +976,2 @@ { key: "Mod-i", run: selectParentSyntax, preventDefault: true }, | ||
export { copyLineDown, copyLineUp, cursorCharBackward, cursorCharForward, cursorCharLeft, cursorCharRight, cursorDocEnd, cursorDocStart, cursorGroupBackward, cursorGroupForward, cursorGroupLeft, cursorGroupRight, cursorLineBoundaryBackward, cursorLineBoundaryForward, cursorLineDown, cursorLineEnd, cursorLineStart, cursorLineUp, cursorMatchingBracket, cursorPageDown, cursorPageUp, cursorSubwordBackward, cursorSubwordForward, cursorSyntaxLeft, cursorSyntaxRight, defaultKeymap, deleteCharBackward, deleteCharForward, deleteGroupBackward, deleteGroupForward, deleteLine, deleteToLineEnd, deleteToLineStart, deleteTrailingWhitespace, emacsStyleKeymap, indentLess, indentMore, indentSelection, indentWithTab, insertNewline, insertNewlineAndIndent, insertTab, moveLineDown, moveLineUp, selectAll, selectCharBackward, selectCharForward, selectCharLeft, selectCharRight, selectDocEnd, selectDocStart, selectGroupBackward, selectGroupForward, selectGroupLeft, selectGroupRight, selectLine, selectLineBoundaryBackward, selectLineBoundaryForward, selectLineDown, selectLineEnd, selectLineStart, selectLineUp, selectMatchingBracket, selectPageDown, selectPageUp, selectParentSyntax, selectSubwordBackward, selectSubwordForward, selectSyntaxLeft, selectSyntaxRight, simplifySelection, splitLine, standardKeymap, transposeChars }; | ||
export { copyLineDown, copyLineUp, cursorCharBackward, cursorCharForward, cursorCharLeft, cursorCharRight, cursorDocEnd, cursorDocStart, cursorGroupBackward, cursorGroupForward, cursorGroupLeft, cursorGroupRight, cursorLineBoundaryBackward, cursorLineBoundaryForward, cursorLineDown, cursorLineEnd, cursorLineStart, cursorLineUp, cursorMatchingBracket, cursorPageDown, cursorPageUp, cursorSubwordBackward, cursorSubwordForward, cursorSyntaxLeft, cursorSyntaxRight, defaultKeymap, deleteCharBackward, deleteCharForward, deleteGroupBackward, deleteGroupForward, deleteLine, deleteToLineEnd, deleteToLineStart, deleteTrailingWhitespace, emacsStyleKeymap, indentLess, indentMore, indentSelection, indentWithTab, insertBlankLine, insertNewline, insertNewlineAndIndent, insertTab, moveLineDown, moveLineUp, selectAll, selectCharBackward, selectCharForward, selectCharLeft, selectCharRight, selectDocEnd, selectDocStart, selectGroupBackward, selectGroupForward, selectGroupLeft, selectGroupRight, selectLine, selectLineBoundaryBackward, selectLineBoundaryForward, selectLineDown, selectLineEnd, selectLineStart, selectLineUp, selectMatchingBracket, selectPageDown, selectPageUp, selectParentSyntax, selectSubwordBackward, selectSubwordForward, selectSyntaxLeft, selectSyntaxRight, simplifySelection, splitLine, standardKeymap, transposeChars }; |
{ | ||
"name": "@codemirror/commands", | ||
"version": "0.19.4", | ||
"version": "0.19.5", | ||
"description": "Collection of editing commands for the CodeMirror code editor", | ||
@@ -5,0 +5,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
122742
2422