prosemirror-codemark
Advanced tools
Comparing version 0.3.1 to 0.3.2
@@ -39,3 +39,3 @@ "use strict"; | ||
const inCode = !!markType.isInSet(pos.marks()); | ||
const nextCode = !!markType.isInSet((_a = pos.marksAcross(doc.resolve(selection.from + 1))) !== null && _a !== void 0 ? _a : []); | ||
const nextCode = !!markType.isInSet((_a = pos.marksAcross((0, utils_1.safeResolve)(doc, selection.from + 1))) !== null && _a !== void 0 ? _a : []); | ||
if (pos.pos === view.state.doc.nodeSize - 3 && (pluginState === null || pluginState === void 0 ? void 0 : pluginState.active)) { | ||
@@ -81,3 +81,3 @@ // Behaviour stops: `code`| at the end of the document | ||
const inCode = !!markType.isInSet(selection.$from.marks()); | ||
const nextCode = !!markType.isInSet((_a = doc.resolve(selection.empty ? selection.from - 1 : selection.from + 1).marks()) !== null && _a !== void 0 ? _a : []); | ||
const nextCode = !!markType.isInSet((_a = (0, utils_1.safeResolve)(doc, selection.empty ? selection.from - 1 : selection.from + 1).marks()) !== null && _a !== void 0 ? _a : []); | ||
if (inCode && (pluginState === null || pluginState === void 0 ? void 0 : pluginState.side) === -1 && selection.$from.parentOffset === 0) { | ||
@@ -168,6 +168,6 @@ // New line! | ||
const { selection, doc } = view.state; | ||
const from = doc.resolve(selection.from - 1); | ||
const from = (0, utils_1.safeResolve)(doc, selection.from - 1); | ||
const fromCode = !!markType.isInSet(from.marks()); | ||
const startOfLine = from.parentOffset === 0; | ||
const toCode = !!markType.isInSet(doc.resolve(selection.to + 1).marks()); | ||
const toCode = !!markType.isInSet((0, utils_1.safeResolve)(doc, selection.to + 1).marks()); | ||
if ((!fromCode || startOfLine) && !toCode) { | ||
@@ -195,3 +195,3 @@ // `x|` β | | ||
const startOfLine = selection.$from.parentOffset === 0; | ||
const toCode = !!markType.isInSet(doc.resolve(selection.to + 2).marks()); | ||
const toCode = !!markType.isInSet((0, utils_1.safeResolve)(doc, selection.to + 2).marks()); | ||
if ((!fromCode || startOfLine) && !toCode) { | ||
@@ -212,3 +212,3 @@ return stepOutsideNextTrAndPass(view, plugin); | ||
const inCode = !!markType.isInSet(selection.$from.marks()); | ||
const nextCode = !!markType.isInSet((_b = doc.resolve(selection.from + 1).marks()) !== null && _b !== void 0 ? _b : []); | ||
const nextCode = !!markType.isInSet((_b = (0, utils_1.safeResolve)(doc, selection.from + 1).marks()) !== null && _b !== void 0 ? _b : []); | ||
const startOfLine = selection.$from.parentOffset === 0; | ||
@@ -215,0 +215,0 @@ // `code|` --> `code`| |
@@ -37,3 +37,3 @@ "use strict"; | ||
apply(tr, value, oldState, state) { | ||
var _a, _b, _c; | ||
var _a; | ||
const meta = tr.getMeta(plugin); | ||
@@ -44,4 +44,4 @@ if ((meta === null || meta === void 0 ? void 0 : meta.action) === 'next') | ||
const nextMark = markType.isInSet((_a = state.storedMarks) !== null && _a !== void 0 ? _a : state.doc.resolve(tr.selection.from).marks()); | ||
const inCode = markType.isInSet((_b = state.doc.resolve(tr.selection.from).marks()) !== null && _b !== void 0 ? _b : []); | ||
const nextCode = markType.isInSet((_c = state.doc.resolve(tr.selection.from + 1).marks()) !== null && _c !== void 0 ? _c : []); | ||
const inCode = markType.isInSet(state.doc.resolve(tr.selection.from).marks()); | ||
const nextCode = markType.isInSet((0, utils_1.safeResolve)(state.doc, tr.selection.from + 1).marks()); | ||
const startOfLine = tr.selection.$from.parentOffset === 0; | ||
@@ -48,0 +48,0 @@ if (!tr.selection.empty) |
@@ -1,2 +0,2 @@ | ||
import { MarkType } from 'prosemirror-model'; | ||
import { MarkType, Node } from 'prosemirror-model'; | ||
import { EditorState, PluginKey } from 'prosemirror-state'; | ||
@@ -9,1 +9,2 @@ import { EditorView } from 'prosemirror-view'; | ||
export declare function getMarkType(view: EditorView | EditorState, opts?: Options): MarkType; | ||
export declare function safeResolve(doc: Node, pos: number): import("prosemirror-model").ResolvedPos<any>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getMarkType = exports.pluginKey = exports.MAX_MATCH = exports.DEFAULT_ID = void 0; | ||
exports.safeResolve = exports.getMarkType = exports.pluginKey = exports.MAX_MATCH = exports.DEFAULT_ID = void 0; | ||
const prosemirror_state_1 = require("prosemirror-state"); | ||
@@ -15,2 +15,6 @@ exports.DEFAULT_ID = 'codemark'; | ||
exports.getMarkType = getMarkType; | ||
function safeResolve(doc, pos) { | ||
return doc.resolve(Math.min(Math.max(1, pos), doc.nodeSize - 2)); | ||
} | ||
exports.safeResolve = safeResolve; | ||
//# sourceMappingURL=utils.js.map |
{ | ||
"name": "prosemirror-codemark", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"description": "Inline code mark for ProseMirror", | ||
@@ -5,0 +5,0 @@ "author": "Rowan Cockett <rowan@curvenote.com>", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
57594
544