@nerd-bible/wordgard 0.5.2-beta3 → 0.5.2-beta4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/command.d.ts +19 -1
- package/dist/command.js +67 -3
- package/dist/editor.d.ts +2 -1
- package/dist/editor.js +3 -2
- package/package.json +2 -2
package/dist/command.d.ts
CHANGED
|
@@ -539,6 +539,24 @@ points.
|
|
|
539
539
|
*/
|
|
540
540
|
declare const deleteToLineEnd: Command<"forward" | "backward">;
|
|
541
541
|
/**
|
|
542
|
+
Command similar to forward `deleteToLineEnd` for macOS's Ctrl-k
|
|
543
|
+
binding. If there's no content left on the line, this will delete
|
|
544
|
+
the node (generally a line break) after the cursor of, if at end
|
|
545
|
+
of textblock, join it to the next textblock.
|
|
546
|
+
|
|
547
|
+
Content deleted by this command is added to a ‘kill buffer’, and
|
|
548
|
+
can be reinserted with {@link yankKilled}. Multiple kill actions
|
|
549
|
+
in sequence will accumulate the deleted content in the buffer.
|
|
550
|
+
Doing anything else and then running this command again will reset
|
|
551
|
+
the buffer to hold only the newly killed content.
|
|
552
|
+
*/
|
|
553
|
+
declare const killToLineEnd: Command;
|
|
554
|
+
/**
|
|
555
|
+
Insert the content killed by the most recent {@link killToLineEnd}
|
|
556
|
+
command (or sequence thereof) at the cursor position.
|
|
557
|
+
*/
|
|
558
|
+
declare const yankKilled: Command;
|
|
559
|
+
/**
|
|
542
560
|
Delete the selection, or if that is empty, the line around the
|
|
543
561
|
cursor.
|
|
544
562
|
*/
|
|
@@ -805,4 +823,4 @@ updated to perform those joins.
|
|
|
805
823
|
*/
|
|
806
824
|
declare function autoJoinBlocks(state: GardState, tr: Transaction.Spec): Transaction.Spec;
|
|
807
825
|
|
|
808
|
-
export { Command, Menu, autoJoinBlocks, canAddMarkInRange, clearNonFitting, deleteBackward, deleteEmptyPlot, deleteForward, deleteLine, deleteSelection, deleteToLineEnd, deleteUnit, deleteWord, doUnwrapBlock, enter, enterInCode, findUnwrappable, findWrappable, insertLineBreak, insertText, joinBackward, joinBlocks, joinForward, joinListItems, liftEmptyBlock, listIsActive, moveByLine, moveByPage, moveByUnit, moveByWord, moveToDocSide, moveToLineSide, moveToTextblockSide, redo, selectAll, selectedTextblocks, setAlignment, setDirection, setTextblockType, splitTextblock, toggleBlock, toggleEmphasis, toggleList, toggleMark, toggleStrong, toggleUnderline, transposeChars, undo, unwrapBlock, wrapBlock, wrapBlockRange };
|
|
826
|
+
export { Command, Menu, autoJoinBlocks, canAddMarkInRange, clearNonFitting, deleteBackward, deleteEmptyPlot, deleteForward, deleteLine, deleteSelection, deleteToLineEnd, deleteUnit, deleteWord, doUnwrapBlock, enter, enterInCode, findUnwrappable, findWrappable, insertLineBreak, insertText, joinBackward, joinBlocks, joinForward, joinListItems, killToLineEnd, liftEmptyBlock, listIsActive, moveByLine, moveByPage, moveByUnit, moveByWord, moveToDocSide, moveToLineSide, moveToTextblockSide, redo, selectAll, selectedTextblocks, setAlignment, setDirection, setTextblockType, splitTextblock, toggleBlock, toggleEmphasis, toggleList, toggleMark, toggleStrong, toggleUnderline, transposeChars, undo, unwrapBlock, wrapBlock, wrapBlockRange, yankKilled };
|
package/dist/command.js
CHANGED
|
@@ -807,7 +807,7 @@ const deleteToLineEnd = (wg, dir) => {
|
|
|
807
807
|
return false;
|
|
808
808
|
let tr = deleteSelection(wg.state), { selection } = wg.state;
|
|
809
809
|
if (tr)
|
|
810
|
-
return
|
|
810
|
+
return tr;
|
|
811
811
|
if (!(selection instanceof GardSelection.Text))
|
|
812
812
|
return false;
|
|
813
813
|
let end = wg.moveToLineBoundary(selection, dir == "forward");
|
|
@@ -819,12 +819,76 @@ const deleteToLineEnd = (wg, dir) => {
|
|
|
819
819
|
userEvent: "delete." + dir
|
|
820
820
|
};
|
|
821
821
|
};
|
|
822
|
+
const addToKillBuffer = /*@__PURE__*/Transaction.Effect.define();
|
|
823
|
+
const killBuffer = /*@__PURE__*/GardState.Field.define({
|
|
824
|
+
create() { return { content: [], active: false }; },
|
|
825
|
+
update(value, tr) {
|
|
826
|
+
let add = tr.effects.find(e => e.is(addToKillBuffer));
|
|
827
|
+
if (add)
|
|
828
|
+
return { content: value.active ? value.content.concat(add.value) : add.value, active: true };
|
|
829
|
+
return !value.active || tr.annotation(Transaction.remote) || !(tr.docChanged || tr.selection)
|
|
830
|
+
? value : { content: value.content, active: false };
|
|
831
|
+
}
|
|
832
|
+
});
|
|
833
|
+
function killText(state, from, to) {
|
|
834
|
+
let add = addToKillBuffer.of(state.doc.slice(from, to).content);
|
|
835
|
+
return state.field(killBuffer, false) ? [add] : [GardState.appendConfig.of(killBuffer), add];
|
|
836
|
+
}
|
|
837
|
+
const killToLineEnd = wg => {
|
|
838
|
+
let { state } = wg, { selection } = state;
|
|
839
|
+
if (state.readOnly || !(selection instanceof GardSelection.Text))
|
|
840
|
+
return false;
|
|
841
|
+
let end = wg.moveToLineBoundary(selection, true);
|
|
842
|
+
if (!end)
|
|
843
|
+
return false;
|
|
844
|
+
if (end.head > selection.head)
|
|
845
|
+
return {
|
|
846
|
+
changes: { correct: { from: selection.head, to: end.head } },
|
|
847
|
+
scrollIntoView: true,
|
|
848
|
+
effects: killText(state, selection.head, end.head),
|
|
849
|
+
userEvent: "delete.forward"
|
|
850
|
+
};
|
|
851
|
+
let join = joinForward(state);
|
|
852
|
+
if (join) {
|
|
853
|
+
let joinEnd;
|
|
854
|
+
state.doc.iterate(state.sel.head.textblockParent.after, state.doc.length, (node, pos) => {
|
|
855
|
+
if (joinEnd != null)
|
|
856
|
+
return false;
|
|
857
|
+
if (node.isPlot && node.isTextblock)
|
|
858
|
+
joinEnd = pos + 1;
|
|
859
|
+
});
|
|
860
|
+
return Transaction.merge(state, join, {
|
|
861
|
+
effects: joinEnd == null ? undefined : killText(state, selection.head, joinEnd)
|
|
862
|
+
});
|
|
863
|
+
}
|
|
864
|
+
let next = state.sel.head.nodeAfter;
|
|
865
|
+
if (next)
|
|
866
|
+
return {
|
|
867
|
+
changes: { correct: { from: selection.head, to: selection.head + next.length } },
|
|
868
|
+
scrollIntoView: true,
|
|
869
|
+
effects: killText(state, selection.head, selection.head + next.length),
|
|
870
|
+
userEvent: "delete.forward"
|
|
871
|
+
};
|
|
872
|
+
return false;
|
|
873
|
+
};
|
|
874
|
+
const yankKilled = wg => {
|
|
875
|
+
let { state } = wg, buffer = wg.state.field(killBuffer, false);
|
|
876
|
+
if (!buffer || !buffer.content.length || !(state.selection instanceof GardSelection.Text))
|
|
877
|
+
return false;
|
|
878
|
+
let { selection } = state;
|
|
879
|
+
return {
|
|
880
|
+
changes: { correct: { from: selection.from, to: selection.to, insert: buffer.content } },
|
|
881
|
+
scrollIntoView: true,
|
|
882
|
+
selection: (cx, changes) => GardSelection.near(cx, changes.mapPos(selection.from, 1)),
|
|
883
|
+
userEvent: "input.yank"
|
|
884
|
+
};
|
|
885
|
+
};
|
|
822
886
|
const deleteLine = wg => {
|
|
823
887
|
if (wg.state.readOnly)
|
|
824
888
|
return false;
|
|
825
889
|
let tr = deleteSelection(wg.state), { selection } = wg.state;
|
|
826
890
|
if (tr)
|
|
827
|
-
return
|
|
891
|
+
return tr;
|
|
828
892
|
if (!(selection instanceof GardSelection.Text))
|
|
829
893
|
return false;
|
|
830
894
|
let start = wg.moveToLineBoundary(selection, false), end = wg.moveToLineBoundary(selection, true);
|
|
@@ -1476,4 +1540,4 @@ const Menu = /*@__PURE__*/(function (Menu) {
|
|
|
1476
1540
|
Menu.resolve = resolve;
|
|
1477
1541
|
;return Menu})({});
|
|
1478
1542
|
|
|
1479
|
-
export { Command, Menu, autoJoinBlocks, canAddMarkInRange, clearNonFitting, deleteBackward, deleteEmptyPlot, deleteForward, deleteLine, deleteSelection, deleteToLineEnd, deleteUnit, deleteWord, doUnwrapBlock, enter, enterInCode, findUnwrappable, findWrappable, insertLineBreak, insertText, joinBackward, joinBlocks, joinForward, joinListItems, liftEmptyBlock, listIsActive, moveByLine, moveByPage, moveByUnit, moveByWord, moveToDocSide, moveToLineSide, moveToTextblockSide, redo, selectAll, selectedTextblocks, setAlignment, setDirection, setTextblockType, splitTextblock, toggleBlock, toggleEmphasis, toggleList, toggleMark, toggleStrong, toggleUnderline, transposeChars, undo, unwrapBlock, wrapBlock, wrapBlockRange };
|
|
1543
|
+
export { Command, Menu, autoJoinBlocks, canAddMarkInRange, clearNonFitting, deleteBackward, deleteEmptyPlot, deleteForward, deleteLine, deleteSelection, deleteToLineEnd, deleteUnit, deleteWord, doUnwrapBlock, enter, enterInCode, findUnwrappable, findWrappable, insertLineBreak, insertText, joinBackward, joinBlocks, joinForward, joinListItems, killToLineEnd, liftEmptyBlock, listIsActive, moveByLine, moveByPage, moveByUnit, moveByWord, moveToDocSide, moveToLineSide, moveToTextblockSide, redo, selectAll, selectedTextblocks, setAlignment, setDirection, setTextblockType, splitTextblock, toggleBlock, toggleEmphasis, toggleList, toggleMark, toggleStrong, toggleUnderline, transposeChars, undo, unwrapBlock, wrapBlock, wrapBlockRange, yankKilled };
|
package/dist/editor.d.ts
CHANGED
|
@@ -1422,11 +1422,12 @@ declare namespace KeyBinding {
|
|
|
1422
1422
|
- `Ctrl-e` to {@link command.moveToTextblockSide} (`{dir: "forward"}`)
|
|
1423
1423
|
- `Ctrl-d` to {@link command.deleteUnit} (`"forward"`)
|
|
1424
1424
|
- `Ctrl-h` to {@link command.deleteUnit} (`"backward"`)
|
|
1425
|
-
- `Ctrl-k` to {@link command.
|
|
1425
|
+
- `Ctrl-k` to {@link command.killToLineEnd}
|
|
1426
1426
|
- `Ctrl-Alt-h` to {@link command.deleteWord} (`"backward"`)
|
|
1427
1427
|
- `Ctrl-o` to {@link command.insertLineBreak}
|
|
1428
1428
|
- `Ctrl-t` to {@link command.transposeChars}
|
|
1429
1429
|
- `Ctrl-v` to {@link command.moveByPage} (`{dir: "down"}`)
|
|
1430
|
+
- `Ctrl-y` to {@link command.yankKilled}
|
|
1430
1431
|
*/
|
|
1431
1432
|
const defaultKeymap: readonly KeyBinding[];
|
|
1432
1433
|
}
|
package/dist/editor.js
CHANGED
|
@@ -2,7 +2,7 @@ import { GardState, GardSelection, TextblockMap, BidiSpan, Transaction } from 'w
|
|
|
2
2
|
import { Attributes, Elt, Node, Leaf, parse, Slice, Plot, serialize, Pos, ChangeSet, ValidationError, Mark } from 'wordgard/doc';
|
|
3
3
|
import { StyleModule } from 'style-mod';
|
|
4
4
|
import { findClusterBreak } from '@marijn/find-cluster-break';
|
|
5
|
-
import { enter, insertLineBreak, selectAll, undo, redo, transposeChars, Command, deleteUnit, deleteWord, deleteToLineEnd, moveByUnit, moveByLine, moveByWord, moveToLineSide, moveToDocSide, moveByPage, moveToTextblockSide, setAlignment, toggleUnderline, toggleEmphasis, toggleStrong, deleteLine, insertText, setDirection, deleteSelection, Menu, findWrappable, wrapBlockRange, autoJoinBlocks } from 'wordgard/command';
|
|
5
|
+
import { enter, insertLineBreak, selectAll, undo, redo, killToLineEnd, yankKilled, transposeChars, Command, deleteUnit, deleteWord, deleteToLineEnd, moveByUnit, moveByLine, moveByWord, moveToLineSide, moveToDocSide, moveByPage, moveToTextblockSide, setAlignment, toggleUnderline, toggleEmphasis, toggleStrong, deleteLine, insertText, setDirection, deleteSelection, Menu, findWrappable, wrapBlockRange, autoJoinBlocks } from 'wordgard/command';
|
|
6
6
|
import { PhraseSet, phrases } from 'wordgard/phrases';
|
|
7
7
|
import { history } from 'wordgard/history';
|
|
8
8
|
|
|
@@ -3946,7 +3946,8 @@ class KeyBinding {
|
|
|
3946
3946
|
shift: Command.bind(moveToTextblockSide, { dir: "forward", extend: true }) },
|
|
3947
3947
|
{ mac: "Ctrl-d", run: Command.bind(deleteUnit, "forward") },
|
|
3948
3948
|
{ mac: "Ctrl-h", run: Command.bind(deleteUnit, "backward") },
|
|
3949
|
-
{ mac: "Ctrl-k", run:
|
|
3949
|
+
{ mac: "Ctrl-k", run: killToLineEnd },
|
|
3950
|
+
{ mac: "Ctrl-y", run: yankKilled },
|
|
3950
3951
|
{ mac: "Ctrl-Alt-h", run: Command.bind(deleteWord, "backward") },
|
|
3951
3952
|
{ mac: "Ctrl-o", run: insertLineBreak },
|
|
3952
3953
|
{ mac: "Ctrl-t", run: transposeChars },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nerd-bible/wordgard",
|
|
3
|
-
"version": "0.5.2-
|
|
3
|
+
"version": "0.5.2-beta4",
|
|
4
4
|
"description": "Semantic rich text editor system",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"style-mod": "^4.1.3"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@nerd-bible/config": "^0.2.
|
|
39
|
+
"@nerd-bible/config": "^0.2.4",
|
|
40
40
|
"@swc/wasm-typescript": "^1.15.3",
|
|
41
41
|
"@types/mocha": "^10.0.10",
|
|
42
42
|
"@types/node": "^24.10.2",
|