Skip to content

Commit

Permalink
remove default conditoin and update conditions as queryNode return tr…
Browse files Browse the repository at this point in the history
…ue when query is undefined
  • Loading branch information
archie9211 committed Oct 9, 2023
1 parent 98de45f commit dffc3d7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 31 deletions.
11 changes: 0 additions & 11 deletions apps/www/src/lib/plate/demo/plugins/deletePlugin.ts

This file was deleted.

2 changes: 0 additions & 2 deletions apps/www/src/registry/default/example/playground-demo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ import { HTML5Backend } from 'react-dnd-html5-backend';

import { ValueId } from '@/config/customizer-plugins';
import { captionPlugin } from '@/lib/plate/demo/plugins/captionPlugin';
import { deletePlugin } from '@/lib/plate/demo/plugins/deletePlugin';
import { cn } from '@/lib/utils';
import { settingsStore } from '@/components/context/settings-store';
import { PlaygroundFixedToolbarButtons } from '@/components/plate-ui/playground-fixed-toolbar-buttons';
Expand Down Expand Up @@ -221,7 +220,6 @@ export const usePlaygroundPlugins = ({
enabled: !!enabled.selectOnBackspace,
}),
createDeletePlugin({
...deletePlugin,
enabled: !!enabled.selectOnBackspace,
}),
createSingleLinePlugin({
Expand Down
26 changes: 9 additions & 17 deletions packages/select/src/withDelete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,16 @@ export const withDelete = <
const { deleteForward } = editor;
editor.deleteForward = (unit: 'character' | 'word' | 'line' | 'block') => {
if (!editor.selection) return;
if (!isSelectionExpanded(editor) && isBlockAboveEmpty(editor)) {
// check when line is empty
const isValidNode = queryNode(getAboveNode(editor), query);
if (query) {
//is query is passed
if (isValidNode) {
// cursor is in query blocks
removeNodes(editor as any);
} else {
//fallback to default behaiour
deleteForward(unit);
}
} else {
// query is not passed, then plugin is active everywhere
removeNodes(editor as any);
}
const isValidNode = queryNode(getAboveNode(editor), query);
if (
!isSelectionExpanded(editor) &&
isBlockAboveEmpty(editor) &&
isValidNode
) {
// Cursor is in query blocks and line is empty
removeNodes(editor as any);
} else {
// when line is not empty, fall back to default behavior
// When the line is not empty or other conditions are not met, fall back to default behavior
deleteForward(unit);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ export const cleanDocxImageElements = (

const alt = element.getAttribute('alt');

if (typeof alt === 'string' && validator.isURL(alt, { require_protocol: true })) {
if (
typeof alt === 'string' &&
validator.isURL(alt, { require_protocol: true })
) {
element.setAttribute('src', alt);
return true;
}
Expand Down

0 comments on commit dffc3d7

Please sign in to comment.