mirror of
https://github.com/codex-team/editor.js
synced 2026-03-16 23:55:49 +01:00
Fix caret behaviour (#1343)
* Fix caret behaviour * Fix current input update
This commit is contained in:
parent
ef5f12bca5
commit
d5f23aa31c
4 changed files with 13 additions and 3 deletions
2
dist/editor.js
vendored
2
dist/editor.js
vendored
File diff suppressed because one or more lines are too long
|
|
@ -21,6 +21,7 @@ import { ToolType } from '../modules/tools';
|
|||
import MoveUpTune from '../block-tunes/block-tune-move-up';
|
||||
import DeleteTune from '../block-tunes/block-tune-delete';
|
||||
import MoveDownTune from '../block-tunes/block-tune-move-down';
|
||||
import SelectionUtils from '../selection';
|
||||
|
||||
/**
|
||||
* Interface describes Block class constructor argument
|
||||
|
|
@ -628,7 +629,11 @@ export default class Block {
|
|||
* Update current input index with selection anchor node
|
||||
*/
|
||||
public updateCurrentInput(): void {
|
||||
this.currentInput = document.activeElement;
|
||||
/**
|
||||
* If activeElement is native input, anchorNode points to its parent.
|
||||
* So if it is native input use it instead of anchorNode
|
||||
*/
|
||||
this.currentInput = $.isNativeInput(document.activeElement) ? document.activeElement : SelectionUtils.anchorNode;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -411,7 +411,7 @@ export default class BlockEvents extends Module {
|
|||
return;
|
||||
}
|
||||
|
||||
const navigateNext = event.keyCode === _.keyCodes.UP || (event.keyCode === _.keyCodes.RIGHT && !this.isRtl);
|
||||
const navigateNext = event.keyCode === _.keyCodes.DOWN || (event.keyCode === _.keyCodes.RIGHT && !this.isRtl);
|
||||
const isNavigated = navigateNext ? this.Editor.Caret.navigateNext() : this.Editor.Caret.navigatePrevious();
|
||||
|
||||
if (isNavigated) {
|
||||
|
|
|
|||
|
|
@ -584,6 +584,11 @@ export default class BlockManager extends Module {
|
|||
*/
|
||||
this.currentBlockIndex = this._blocks.nodes.indexOf(parentFirstLevelBlock as HTMLElement);
|
||||
|
||||
/**
|
||||
* Update current block active input
|
||||
*/
|
||||
this.currentBlock.updateCurrentInput();
|
||||
|
||||
return this.currentBlock;
|
||||
} else {
|
||||
throw new Error('Can not find a Block from this child Node');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue