mirror of
https://github.com/codex-team/editor.js
synced 2024-06-10 18:03:25 +02:00
use atStartOfInput instead of atStartOfFirstInput
This commit is contained in:
parent
bb7377c1e1
commit
bb7e112a97
|
@ -263,12 +263,18 @@ export default class CrossInputSelection extends Module {
|
|||
const api = this.Editor.API.methods;
|
||||
|
||||
useCrossInputSelection(api, {
|
||||
atStartOfFirstInput: ({ input, block }, { mergeOrNavigatePrevious }) => {
|
||||
atStartOfInput: ({ input, block }, { mergeOrNavigatePrevious }) => {
|
||||
console.log('Delete / atStartOfFirstInput: merge or navigate to the previous block');
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
mergeOrNavigatePrevious();
|
||||
const isFirstInputInBlock = input === block.inputs[0];
|
||||
|
||||
if (isFirstInputInBlock) {
|
||||
mergeOrNavigatePrevious();
|
||||
} else {
|
||||
this.Editor.Caret.navigatePrevious();
|
||||
}
|
||||
},
|
||||
onSingleFullySelectedInput: ({ input }, { clear }) => {
|
||||
console.info('Delete / onSingleFullySelectedInput: clear input');
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
import type { API, BlockAPI } from '@types';
|
||||
import { getClosestElement } from '../dom';
|
||||
import Dom, { getClosestElement } from '../dom';
|
||||
import { isEmpty } from './empty';
|
||||
import { isAtStart } from './selection'
|
||||
|
||||
|
@ -234,8 +234,8 @@ interface CBSOptions {
|
|||
onSingleFullySelectedInput?: (input: BlockInputIntersected, helpers: CBSHelpers) => void;
|
||||
onSinglePartiallySelectedInput?: (input: BlockInputIntersected) => void;
|
||||
onCrossInputSelection?: (selection: CrossInputSelection) => void;
|
||||
atStartOfFirstInput?: (input: BlockInputIntersected) => void;
|
||||
atEndOfLastInput?: () => void;
|
||||
atStartOfInput?: (input: BlockInputIntersected) => void;
|
||||
atEndOfInput?: (input: BlockInputIntersected) => void;
|
||||
}
|
||||
|
||||
function insertChar(char: string): void {
|
||||
|
@ -305,7 +305,7 @@ export function useCrossInputSelection(api: API, options?: CBSOptions): MaybeCro
|
|||
|
||||
const isCrossBlockSelection = intersectedBlocks.length > 1;
|
||||
|
||||
const firstBlock = intersectedBlocks[0];
|
||||
const firstBlock = intersectedBlocks[0]; // startingBlock?
|
||||
const lastBlock = intersectedBlocks[intersectedBlocks.length - 1];
|
||||
const firstInput = intersectedInputs[0] ?? null;
|
||||
const lastInput = intersectedInputs[intersectedInputs.length - 1] ?? null;
|
||||
|
@ -323,7 +323,8 @@ export function useCrossInputSelection(api: API, options?: CBSOptions): MaybeCro
|
|||
|
||||
if (intersectedInputs.length === 1) {
|
||||
const { input, block } = firstInput;
|
||||
const isWholeInputSelected = range.toString() === input.textContent;
|
||||
const isInputEmpty = Dom.isEmpty(input);
|
||||
const isWholeInputSelected = !isInputEmpty && range.toString() === input.textContent;
|
||||
const atStart = isAtStart(firstInput?.input);
|
||||
|
||||
if (isWholeInputSelected) {
|
||||
|
@ -347,7 +348,7 @@ export function useCrossInputSelection(api: API, options?: CBSOptions): MaybeCro
|
|||
} else if (atStart) {
|
||||
const mergeOrNavigatePrevious = async function mergeOrNavigatePrevious() {
|
||||
/**
|
||||
* In this case first and last block are the same, so we need find previous one
|
||||
* In this a case when the first and the last block are the same we need to find a previous one
|
||||
*/
|
||||
const lastBlockIndex = api.blocks.getBlockIndex(lastBlock.id);
|
||||
|
||||
|
@ -364,7 +365,7 @@ export function useCrossInputSelection(api: API, options?: CBSOptions): MaybeCro
|
|||
await mergeOrNavigate(api, previousBlock, lastBlock);
|
||||
}
|
||||
|
||||
options?.atStartOfFirstInput?.(firstInput, { mergeOrNavigatePrevious });
|
||||
options?.atStartOfInput?.(firstInput, { mergeOrNavigatePrevious });
|
||||
} else {
|
||||
options?.onSinglePartiallySelectedInput?.(firstInput);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue