prosemirror-commands
Advanced tools
Comparing version 1.1.12 to 1.2.0
@@ -0,1 +1,13 @@ | ||
## 1.2.0 (2022-01-17) | ||
### Bug fixes | ||
Add a workaround for a bug on macOS where Ctrl-a and Ctrl-e getting stuck at the edge of inline nodes. | ||
### New features | ||
The new `selectTextblockEnd` and `selectTextblockStart` commands move the cursor to the start/end of the textblock, when inside one. | ||
Ctrl-a/e on macOS and Home/End on other platforms are now bound to `selectTextblockEnd` and `selectTextblockStart`. | ||
## 1.1.12 (2021-10-29) | ||
@@ -2,0 +14,0 @@ |
@@ -458,2 +458,26 @@ import { liftTarget, canJoin, joinPoint, canSplit, ReplaceAroundStep, findWrapping } from 'prosemirror-transform'; | ||
function selectTextblockSide(side) { | ||
return function(state, dispatch) { | ||
var sel = state.selection, $pos = side < 0 ? sel.$from : sel.$to; | ||
var depth = $pos.depth; | ||
while ($pos.node(depth).isInline) { | ||
if (!depth) { return false } | ||
depth--; | ||
} | ||
if (!$pos.node(depth).isTextblock) { return false } | ||
if (dispatch) | ||
{ dispatch(state.tr.setSelection(TextSelection.create( | ||
state.doc, side < 0 ? $pos.start(depth) : $pos.end(depth)))); } | ||
return true | ||
} | ||
} | ||
// :: (EditorState, ?(tr: Transaction)) → bool | ||
// Moves the cursor to the start of current text block. | ||
var selectTextblockStart = selectTextblockSide(-1); | ||
// :: (EditorState, ?(tr: Transaction)) → bool | ||
// Moves the cursor to the end of current text block. | ||
var selectTextblockEnd = selectTextblockSide(1); | ||
// Parameterized commands | ||
@@ -675,6 +699,11 @@ | ||
"Alt-Delete": pcBaseKeymap["Mod-Delete"], | ||
"Alt-d": pcBaseKeymap["Mod-Delete"] | ||
"Alt-d": pcBaseKeymap["Mod-Delete"], | ||
"Ctrl-a": selectTextblockStart, | ||
"Ctrl-e": selectTextblockEnd | ||
}; | ||
for (var key in pcBaseKeymap) { macBaseKeymap[key] = pcBaseKeymap[key]; } | ||
pcBaseKeymap.Home = selectTextblockStart; | ||
pcBaseKeymap.End = selectTextblockEnd; | ||
// declare global: os, navigator | ||
@@ -690,3 +719,3 @@ var mac = typeof navigator != "undefined" ? /Mac|iP(hone|[oa]d)/.test(navigator.platform) | ||
export { autoJoin, baseKeymap, chainCommands, createParagraphNear, deleteSelection, exitCode, joinBackward, joinDown, joinForward, joinUp, lift, liftEmptyBlock, macBaseKeymap, newlineInCode, pcBaseKeymap, selectAll, selectNodeBackward, selectNodeForward, selectParentNode, setBlockType, splitBlock, splitBlockKeepMarks, toggleMark, wrapIn }; | ||
export { autoJoin, baseKeymap, chainCommands, createParagraphNear, deleteSelection, exitCode, joinBackward, joinDown, joinForward, joinUp, lift, liftEmptyBlock, macBaseKeymap, newlineInCode, pcBaseKeymap, selectAll, selectNodeBackward, selectNodeForward, selectParentNode, selectTextblockEnd, selectTextblockStart, setBlockType, splitBlock, splitBlockKeepMarks, toggleMark, wrapIn }; | ||
//# sourceMappingURL=index.es.js.map |
@@ -462,2 +462,26 @@ 'use strict'; | ||
function selectTextblockSide(side) { | ||
return function(state, dispatch) { | ||
var sel = state.selection, $pos = side < 0 ? sel.$from : sel.$to; | ||
var depth = $pos.depth; | ||
while ($pos.node(depth).isInline) { | ||
if (!depth) { return false } | ||
depth--; | ||
} | ||
if (!$pos.node(depth).isTextblock) { return false } | ||
if (dispatch) | ||
{ dispatch(state.tr.setSelection(prosemirrorState.TextSelection.create( | ||
state.doc, side < 0 ? $pos.start(depth) : $pos.end(depth)))); } | ||
return true | ||
} | ||
} | ||
// :: (EditorState, ?(tr: Transaction)) → bool | ||
// Moves the cursor to the start of current text block. | ||
var selectTextblockStart = selectTextblockSide(-1); | ||
// :: (EditorState, ?(tr: Transaction)) → bool | ||
// Moves the cursor to the end of current text block. | ||
var selectTextblockEnd = selectTextblockSide(1); | ||
// Parameterized commands | ||
@@ -679,6 +703,11 @@ | ||
"Alt-Delete": pcBaseKeymap["Mod-Delete"], | ||
"Alt-d": pcBaseKeymap["Mod-Delete"] | ||
"Alt-d": pcBaseKeymap["Mod-Delete"], | ||
"Ctrl-a": selectTextblockStart, | ||
"Ctrl-e": selectTextblockEnd | ||
}; | ||
for (var key in pcBaseKeymap) { macBaseKeymap[key] = pcBaseKeymap[key]; } | ||
pcBaseKeymap.Home = selectTextblockStart; | ||
pcBaseKeymap.End = selectTextblockEnd; | ||
// declare global: os, navigator | ||
@@ -713,2 +742,4 @@ var mac = typeof navigator != "undefined" ? /Mac|iP(hone|[oa]d)/.test(navigator.platform) | ||
exports.selectParentNode = selectParentNode; | ||
exports.selectTextblockEnd = selectTextblockEnd; | ||
exports.selectTextblockStart = selectTextblockStart; | ||
exports.setBlockType = setBlockType; | ||
@@ -715,0 +746,0 @@ exports.splitBlock = splitBlock; |
{ | ||
"name": "prosemirror-commands", | ||
"version": "1.1.12", | ||
"version": "1.2.0", | ||
"description": "Editing commands for ProseMirror", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -435,2 +435,26 @@ import {joinPoint, canJoin, findWrapping, liftTarget, canSplit, ReplaceAroundStep} from "prosemirror-transform" | ||
function selectTextblockSide(side) { | ||
return function(state, dispatch) { | ||
let sel = state.selection, $pos = side < 0 ? sel.$from : sel.$to | ||
let depth = $pos.depth | ||
while ($pos.node(depth).isInline) { | ||
if (!depth) return false | ||
depth-- | ||
} | ||
if (!$pos.node(depth).isTextblock) return false | ||
if (dispatch) | ||
dispatch(state.tr.setSelection(TextSelection.create( | ||
state.doc, side < 0 ? $pos.start(depth) : $pos.end(depth)))) | ||
return true | ||
} | ||
} | ||
// :: (EditorState, ?(tr: Transaction)) → bool | ||
// Moves the cursor to the start of current text block. | ||
export const selectTextblockStart = selectTextblockSide(-1) | ||
// :: (EditorState, ?(tr: Transaction)) → bool | ||
// Moves the cursor to the end of current text block. | ||
export const selectTextblockEnd = selectTextblockSide(1) | ||
// Parameterized commands | ||
@@ -630,6 +654,11 @@ | ||
"Alt-Delete": pcBaseKeymap["Mod-Delete"], | ||
"Alt-d": pcBaseKeymap["Mod-Delete"] | ||
"Alt-d": pcBaseKeymap["Mod-Delete"], | ||
"Ctrl-a": selectTextblockStart, | ||
"Ctrl-e": selectTextblockEnd | ||
} | ||
for (let key in pcBaseKeymap) macBaseKeymap[key] = pcBaseKeymap[key] | ||
pcBaseKeymap.Home = selectTextblockStart | ||
pcBaseKeymap.End = selectTextblockEnd | ||
// declare global: os, navigator | ||
@@ -636,0 +665,0 @@ const mac = typeof navigator != "undefined" ? /Mac|iP(hone|[oa]d)/.test(navigator.platform) |
@@ -29,2 +29,4 @@ This module exports a number of _commands_, which are building block | ||
@selectAll | ||
@selectTextblockStart | ||
@selectTextblockEnd | ||
@wrapIn | ||
@@ -31,0 +33,0 @@ @setBlockType |
Sorry, the diff of this file is not supported yet
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
212813
1960