Merge pull request #149 from toeverything/bugfix/Cursor-move-up-and-down

fix Cursor move up and down error
This commit is contained in:
DarkSky 2022-08-08 23:35:44 +08:00 committed by GitHub
commit b3b4a587c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -126,7 +126,7 @@ export const TextManage = forwardRef<ExtendedTextUtils, CreateTextView>(
// block = await editor.commands.blockCommands.createNextBlock(block.id,) // block = await editor.commands.blockCommands.createNextBlock(block.id,)
const on_text_view_active = useCallback( const on_text_view_active = useCallback(
(point: CursorTypes, rang_form?: 'up' | 'down') => { (point: CursorTypes) => {
// TODO code to be optimized // TODO code to be optimized
if (textRef.current) { if (textRef.current) {
const end_selection = textRef.current.getEndSelection(); const end_selection = textRef.current.getEndSelection();
@ -146,7 +146,7 @@ export const TextManage = forwardRef<ExtendedTextUtils, CreateTextView>(
.getElementsByClassName('text-paragraph')[0] .getElementsByClassName('text-paragraph')[0]
.getBoundingClientRect(); .getBoundingClientRect();
if (rang_form === 'up') { if (blockTop > blockDomStyle.top) {
blockTop = blockDomStyle.bottom - 5; blockTop = blockDomStyle.bottom - 5;
} else { } else {
blockTop = blockDomStyle.top + 5; blockTop = blockDomStyle.top + 5;
@ -319,7 +319,7 @@ export const TextManage = forwardRef<ExtendedTextUtils, CreateTextView>(
if (nowPosition.top === startPosition.top) { if (nowPosition.top === startPosition.top) {
editor.selectionManager.activePreviousNode( editor.selectionManager.activePreviousNode(
block.id, block.id,
new Point(nowPosition.left, nowPosition.top - 20) new Point(nowPosition.left, nowPosition.top)
); );
return true; return true;
@ -357,17 +357,14 @@ export const TextManage = forwardRef<ExtendedTextUtils, CreateTextView>(
// The specific amount of TODO needs to be determined after subsequent padding // The specific amount of TODO needs to be determined after subsequent padding
editor.selectionManager.activeNextNode( editor.selectionManager.activeNextNode(
block.id, block.id,
new Point(nowPosition.left, nowPosition.bottom + 20) new Point(nowPosition.left, nowPosition.bottom)
); );
return true; return true;
} else { } else {
if (prePosition?.bottom === endPosition.bottom) { if (prePosition?.bottom === endPosition.bottom) {
editor.selectionManager.activeNextNode( editor.selectionManager.activeNextNode(
block.id, block.id,
new Point( new Point(prePosition.left, prePosition?.bottom)
prePosition.left,
prePosition?.bottom + 20
)
); );
return true; return true;
} else { } else {