mirror of
https://github.com/codex-team/editor.js
synced 2024-05-20 15:26:48 +02:00
issue-469: resolving error with setCaret (#570)
* issue-469: resolving error with setCaret * dump version * update package.json * expand input types
This commit is contained in:
parent
71a8a99937
commit
41ae41cda7
12
dist/codex-editor.js
vendored
12
dist/codex-editor.js
vendored
File diff suppressed because one or more lines are too long
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "codex.editor",
|
||||
"version": "2.7.13",
|
||||
"version": "2.7.14",
|
||||
"description": "CodeX Editor. Native JS, based on API and Open Source",
|
||||
"main": "dist/codex-editor.js",
|
||||
"types": "./types/index.d.ts",
|
||||
|
|
|
@ -241,6 +241,15 @@ export default class Dom {
|
|||
return node && typeof node === 'object' && node.nodeType && node.nodeType === Node.DOCUMENT_FRAGMENT_NODE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if passed element is contenteditable
|
||||
* @param {HTMLElement} element
|
||||
* @return {boolean}
|
||||
*/
|
||||
public static isContentEditable(element: HTMLElement): boolean {
|
||||
return element.contentEditable === 'true';
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks target if it is native input
|
||||
* @param {Element|String|Node} target - HTML element or string
|
||||
|
@ -255,6 +264,33 @@ export default class Dom {
|
|||
return target && target.tagName ? nativeInputs.includes(target.tagName) : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if we can set caret
|
||||
* @param {HTMLElement} target
|
||||
* @return {boolean}
|
||||
*/
|
||||
public static canSetCaret(target: HTMLElement): boolean {
|
||||
let result = true;
|
||||
if (Dom.isNativeInput(target)) {
|
||||
const inputElement = target as HTMLInputElement;
|
||||
switch (inputElement.type) {
|
||||
case 'file':
|
||||
case 'checkbox':
|
||||
case 'radio':
|
||||
case 'hidden':
|
||||
case 'submit':
|
||||
case 'button':
|
||||
case 'image':
|
||||
case 'reset':
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
result = Dom.isContentEditable(target);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks node if it is empty
|
||||
*
|
||||
|
|
|
@ -247,6 +247,10 @@ export default class Caret extends Module {
|
|||
|
||||
/** if found deepest node is native input */
|
||||
if ($.isNativeInput(element)) {
|
||||
if (!$.canSetCaret(element)) {
|
||||
return;
|
||||
}
|
||||
|
||||
element.focus();
|
||||
(element as HTMLInputElement).selectionStart = (element as HTMLInputElement).selectionEnd = offset;
|
||||
return;
|
||||
|
|
|
@ -185,15 +185,6 @@ export default class Util {
|
|||
return Promise.resolve(object) === object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if passed element is contenteditable
|
||||
* @param {HTMLElement} element
|
||||
* @return {boolean}
|
||||
*/
|
||||
public static isContentEditable(element: HTMLElement): boolean {
|
||||
return element.contentEditable === 'true';
|
||||
}
|
||||
|
||||
/**
|
||||
* Delays method execution
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue