forked from steven-tey/novel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
73e0530
commit c2892fb
Showing
3 changed files
with
51 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,56 @@ | ||
import { Extension } from '@tiptap/core'; | ||
import { Extension } from "@tiptap/core"; | ||
|
||
declare module '@tiptap/core' { | ||
interface Commands<ReturnType> { | ||
customkeymap: { | ||
/** | ||
* Select text between node boundaries | ||
*/ | ||
selectTextWithinNodeBoundaries: () => ReturnType; | ||
}; | ||
} | ||
declare module "@tiptap/core" { | ||
// eslint-disable-next-line no-unused-vars | ||
interface Commands<ReturnType> { | ||
customkeymap: { | ||
/** | ||
* Select text between node boundaries | ||
*/ | ||
selectTextWithinNodeBoundaries: () => ReturnType; | ||
}; | ||
} | ||
} | ||
|
||
const CustomKeymap = Extension.create({ | ||
name: 'CustomKeymap', | ||
name: "CustomKeymap", | ||
|
||
addCommands() { | ||
return { | ||
selectTextWithinNodeBoundaries: () => ({ editor, commands }) => { | ||
const { state } = editor; | ||
const { tr } = state; | ||
const startNodePos = tr.selection.$from.start(); | ||
const endNodePos = tr.selection.$to.end(); | ||
return commands.setTextSelection({ from: startNodePos, to: endNodePos }); | ||
}, | ||
}; | ||
}, | ||
addCommands() { | ||
return { | ||
selectTextWithinNodeBoundaries: | ||
() => | ||
({ editor, commands }) => { | ||
const { state } = editor; | ||
const { tr } = state; | ||
const startNodePos = tr.selection.$from.start(); | ||
const endNodePos = tr.selection.$to.end(); | ||
return commands.setTextSelection({ | ||
from: startNodePos, | ||
to: endNodePos, | ||
}); | ||
}, | ||
}; | ||
}, | ||
|
||
addKeyboardShortcuts() { | ||
return { | ||
'Mod-a': ({ editor }) => { | ||
const { state } = editor; | ||
const { tr } = state; | ||
const startSelectionPos = tr.selection.from; | ||
const endSelectionPos = tr.selection.to; | ||
const startNodePos = tr.selection.$from.start(); | ||
const endNodePos = tr.selection.$to.end(); | ||
const isCurrentTextSelectionNotExtendedToNodeBoundaries = | ||
startSelectionPos > startNodePos || endSelectionPos < endNodePos; | ||
if (isCurrentTextSelectionNotExtendedToNodeBoundaries) { | ||
editor.chain().selectTextWithinNodeBoundaries().run(); | ||
return true; | ||
} | ||
return false; | ||
}, | ||
}; | ||
}, | ||
addKeyboardShortcuts() { | ||
return { | ||
"Mod-a": ({ editor }) => { | ||
const { state } = editor; | ||
const { tr } = state; | ||
const startSelectionPos = tr.selection.from; | ||
const endSelectionPos = tr.selection.to; | ||
const startNodePos = tr.selection.$from.start(); | ||
const endNodePos = tr.selection.$to.end(); | ||
const isCurrentTextSelectionNotExtendedToNodeBoundaries = | ||
startSelectionPos > startNodePos || endSelectionPos < endNodePos; | ||
if (isCurrentTextSelectionNotExtendedToNodeBoundaries) { | ||
editor.chain().selectTextWithinNodeBoundaries().run(); | ||
return true; | ||
} | ||
return false; | ||
}, | ||
}; | ||
}, | ||
}); | ||
|
||
export default CustomKeymap; | ||
export default CustomKeymap; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters