Fix caret behaviour (#1343)

* Fix caret behaviour

* Fix current input update
This commit is contained in:
George Berezhnoy 2020-10-06 20:31:27 +03:00 committed by GitHub
commit d5f23aa31c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 3 deletions

2
dist/editor.js vendored

File diff suppressed because one or more lines are too long

View file

@ -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;
}
/**

View file

@ -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) {

View file

@ -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');