Skip to content

Commit

Permalink
fix eslint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
steven-tey committed Sep 4, 2023
1 parent 73e0530 commit c2892fb
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 44 deletions.
90 changes: 48 additions & 42 deletions packages/core/src/ui/editor/extensions/custom-keymap.ts
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;
2 changes: 1 addition & 1 deletion packages/core/src/ui/editor/extensions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,6 @@ export const defaultExtensions = [
html: false,
transformCopiedText: true,
}),
CustomKeymap
CustomKeymap,
DragAndDrop,
];
3 changes: 2 additions & 1 deletion packages/core/src/ui/editor/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-unused-vars */
"use client";

import { useEffect, useRef, useState } from "react";
Expand Down Expand Up @@ -62,11 +61,13 @@ export default function Editor({
* A callback function that is called whenever the editor is updated.
* Defaults to () => {}.
*/
// eslint-disable-next-line no-unused-vars
onUpdate?: (editor?: EditorClass) => void | Promise<void>;
/**
* A callback function that is called whenever the editor is updated, but only after the defined debounce duration.
* Defaults to () => {}.
*/
// eslint-disable-next-line no-unused-vars
onDebouncedUpdate?: (editor?: EditorClass) => void | Promise<void>;
/**
* The duration (in milliseconds) to debounce the onDebouncedUpdate callback.
Expand Down

0 comments on commit c2892fb

Please sign in to comment.