mirror of
https://github.com/codex-team/editor.js
synced 2024-06-19 22:25:23 +02:00
Fix jumping caret bug (#568)
* Fix jumping caret bug * Get element from point
This commit is contained in:
parent
cfae683d6a
commit
5b156c1875
12
dist/codex-editor.js
vendored
12
dist/codex-editor.js
vendored
File diff suppressed because one or more lines are too long
52
dist/codex-editor.licenses.txt
vendored
52
dist/codex-editor.licenses.txt
vendored
|
@ -76,6 +76,32 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
regenerator-runtime
|
||||
MIT
|
||||
|
||||
@babel/register
|
||||
MIT
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2014-2018 Sebastian McKenzie <sebmck@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
|
||||
codex-notifier
|
||||
MIT
|
||||
MIT License
|
||||
|
@ -376,29 +402,3 @@ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
|
||||
@babel/register
|
||||
MIT
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2014-2018 Sebastian McKenzie <sebmck@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "codex.editor",
|
||||
"version": "2.7.16",
|
||||
"version": "2.7.17",
|
||||
"description": "CodeX Editor. Native JS, based on API and Open Source",
|
||||
"main": "dist/codex-editor.js",
|
||||
"types": "./types/index.d.ts",
|
||||
|
|
|
@ -137,7 +137,7 @@ export default class InlineToolbar extends Module {
|
|||
* @param {KeyboardEvent|MouseEvent} event
|
||||
*/
|
||||
public handleShowingEvent(event): void {
|
||||
if (!this.allowedToShow(event)) {
|
||||
if (!this.allowedToShow()) {
|
||||
this.close();
|
||||
return;
|
||||
}
|
||||
|
@ -183,7 +183,7 @@ export default class InlineToolbar extends Module {
|
|||
*/
|
||||
public close(): void {
|
||||
this.nodes.wrapper.classList.remove(this.CSS.inlineToolbarShowed);
|
||||
this.tools.forEach((toolInstance, toolName) => {
|
||||
this.tools.forEach((toolInstance) => {
|
||||
if (typeof toolInstance.clear === 'function') {
|
||||
toolInstance.clear();
|
||||
}
|
||||
|
@ -216,27 +216,15 @@ export default class InlineToolbar extends Module {
|
|||
|
||||
/**
|
||||
* Need to show Inline Toolbar or not
|
||||
* @param {KeyboardEvent|MouseEvent} event
|
||||
*/
|
||||
private allowedToShow(event): boolean {
|
||||
private allowedToShow(): boolean {
|
||||
/**
|
||||
* Tags conflicts with window.selection function.
|
||||
* Ex. IMG tag returns null (Firefox) or Redactors wrapper (Chrome)
|
||||
*/
|
||||
const tagsConflictsWithSelection = ['IMG', 'INPUT'];
|
||||
|
||||
if (event && tagsConflictsWithSelection.includes(event.target.tagName)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// The selection of the element only in contenteditable
|
||||
const contenteditable = event.target.closest('[contenteditable="true"]');
|
||||
if (contenteditable === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const currentSelection = SelectionUtils.get(),
|
||||
selectedText = SelectionUtils.text;
|
||||
const currentSelection = SelectionUtils.get();
|
||||
const selectedText = SelectionUtils.text;
|
||||
|
||||
// old browsers
|
||||
if (!currentSelection || !currentSelection.anchorNode) {
|
||||
|
@ -248,6 +236,18 @@ export default class InlineToolbar extends Module {
|
|||
return false;
|
||||
}
|
||||
|
||||
const target = currentSelection.anchorNode.parentElement;
|
||||
|
||||
if (currentSelection && tagsConflictsWithSelection.includes(target.tagName)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// The selection of the element only in contenteditable
|
||||
const contenteditable = target.closest('[contenteditable="true"]');
|
||||
if (contenteditable === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// is enabled by current Block's Tool
|
||||
const currentBlock = this.Editor.BlockManager.getBlock(currentSelection.anchorNode as HTMLElement);
|
||||
|
||||
|
@ -367,7 +367,7 @@ export default class InlineToolbar extends Module {
|
|||
|
||||
return (toolClass as ToolSettings).class[Tools.apiSettings.IS_INLINE];
|
||||
})
|
||||
.map(([name, toolClass]: [string, InlineToolConstructable | ToolSettings]) => name);
|
||||
.map(([name]: [string, InlineToolConstructable | ToolSettings]) => name);
|
||||
|
||||
/**
|
||||
* 1) For internal tools, check public getter 'shortcut'
|
||||
|
|
|
@ -290,7 +290,19 @@ export default class UI extends Module {
|
|||
*
|
||||
*/
|
||||
private redactorClicked(event: MouseEvent): void {
|
||||
const clickedNode = event.target as HTMLElement;
|
||||
|
||||
if (!Selection.isCollapsed) {
|
||||
return;
|
||||
}
|
||||
|
||||
let clickedNode = event.target as HTMLElement;
|
||||
|
||||
/**
|
||||
* If click was fired is on Editor`s wrapper, try to get clicked node by elementFromPoint method
|
||||
*/
|
||||
if (clickedNode === this.nodes.redactor) {
|
||||
clickedNode = document.elementFromPoint(event.clientX, event.clientY) as HTMLElement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Select clicked Block as Current
|
||||
|
|
Loading…
Reference in a new issue